我正在创建 Android 笔记应用程序,并希望添加编辑通知中存储的笔记的功能。那么我可以将初始文本从当前注释(通知)添加到 Android RemoteInput 并允许用户更改它吗?
示例:我需要将通知中的“hello world”文本设置为“type note”远程输入字段。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Intent editIntent = new Intent(ACTION_EDIT, null, context, EditReceiver.class);
editIntent.setAction(ACTION_EDIT);
editIntent.putExtra(NOTIFICATION_ID, id);
PendingIntent replyPendingIntent =
PendingIntent.getBroadcast(context, id, editIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteInput remoteInput = new RemoteInput.Builder(EDIT_TEXT)
.setLabel(TYPE_NOTE)
.build();
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_send,
EDIT, replyPendingIntent)
.addRemoteInput(remoteInput)
.build();
mBuilder.addAction(action);
mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.pushpinsm));
}