0

我正在创建 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));
}
4

1 回答 1

0

我认为不可能设置初始消息。

如果您有关于设置标签的问题,此代码将在 RemoteInput 中设置标签。

RemoteInput remoteInput = new RemoteInput.Builder(EDIT_TEXT)
    .setLabel(TYPE_NOTE)
    .build();
于 2021-05-24T12:32:54.797 回答