Is it possible to add initial text to notification RemoteInput (Android)?

292 Views Asked by At

I am creating Android notes app and want to add ability to edit note that stores in notification. So can I add initial text to Android RemoteInput from the current note(notification) and allow user to change it?

example of note(notification)

Example: I need to set 'hello world' text from the notification to the 'type note' RemoteInput field.

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));
}
1

There are 1 best solutions below

0
On

I think it's not possible to set initial message.

If your question about set the label, this code will set the label in RemoteInput.

RemoteInput remoteInput = new RemoteInput.Builder(EDIT_TEXT)
    .setLabel(TYPE_NOTE)
    .build();