我的应用程序使用a NotificationListener来读取来自各种第三方应用程序的消息,例如WhatsApp.
到目前为止,如果只有一个聊天未读,我能够发送回复,代码如下.
但是,在WhatsApp的情况下,getNotification().actions当未读取两个以上的聊天时返回一个空对象,因为消息被捆绑在一起.正如您在下面的图片中看到的,如果通知被扩展,还有一个选项可以发送直接回复,因此我确信可以利用它,我认为像PushBullet这样的应用程序正在使用此方法.
我怎样才能访问该通知的RemoteInput?
public static ReplyIntentSender sendReply(StatusBarNotification statusBarNotification, String name) {
Notification.Action actions[] = statusBarNotification.getNotification().actions;
for (Notification.Action act : actions) {
if (act != null && act.getRemoteInputs() != null) {
if (act.title.toString().contains(name)) {
if (act.getRemoteInputs() != null)
return new ReplyIntentSender(act);
}
}
}
return null;
}
public static class ReplyIntentSender {
[...]
public final Notification.Action action;
public ReplyIntentSender(Notification.Action extractedAction) {
action = extractedAction;
[...]
}
private boolean sendNativeIntent(Context context, String message) {
for (android.app.RemoteInput rem …Run Code Online (Sandbox Code Playgroud) android notification-listener android-7.0-nougat remote-input
有一个所谓的新功能setAllowDataType上RemoteInput.Builder的API 26这是什么用的呢?我尝试了以下方法:
val remoteInput = RemoteInput.Builder(KEY_TEXT_REPLY)
.setLabel("Image")
.setAllowFreeFormInput(false)
.setChoices(null)
.setAllowDataType("image/*", true)
.setAllowDataType("image/png", true)
.setAllowDataType("image/jpg", true)
.setAllowDataType("image/gif", true)
.build()
Run Code Online (Sandbox Code Playgroud)
这应该设置isDataOnly到true的RemoteInput,但通知出现为手机上的以下.单击Image按钮不会执行任何操作.这个是来做什么的?我找不到有关此功能的任何文档,发行说明或教程.

实际发布通知时,看起来通知中缺少仅数据类型.查看构建器代码,在添加Actions到通知时,它使用级别24完全去除数据类型:https://android.googlesource.com/platform/frameworks/support/+/oreo-release/compat/api26/安卓/支持/ V4 /应用/ NotificationCompatApi26.java#108
原始问题仍然存在.
我在Android N通知中使用RemoteInput.
我想为输入设置最小和最大文本长度限制.
Google Hangouts获得此功能(即当用户输入至少1个字符时启用发送按钮).任何人都知道如何做到这一点?我试过检查Android文档,但没有运气.
我正在显示这样的通知RemoteInput:
RemoteInput remoteInput = new RemoteInput.Builder("key_add_note")
.setLabel("add note")
.build();
PendingIntent AddNotePendingIntent =
PendingIntent.getBroadcast(getApplicationContext(),
(int) txn.get_id(),
new Intent(getApplicationContext(), AddNoteBroadcastReceiver.class)
.putExtra(Constants.IntentExtras.STA_TXN_ID, txn.get_id()),
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.ic_action_edit_dark,
"add note", AddNotePendingIntent)
.addRemoteInput(remoteInput)
.build();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationUtil.MISC_CHANNEL_ID)
.setContentTitle("TEST")
.setContentText("add Note")
.setSmallIcon(R.drawable.ic_action_edit_dark)
.setAutoCancel(true)
.addAction(action);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(123456, builder.build());
Run Code Online (Sandbox Code Playgroud)
输出:
单击添加注释,输入文本并提交后,我尝试取消通知,如下所示:
notificationManager.cancel(123456);
Run Code Online (Sandbox Code Playgroud)
这不会取消通知,而只是关闭输入字段,并在我的通知下方附加文本,如下所示:
为什么这不会取消通知?以及如何取消。
更新:即使有带通知的标签,结果也一样