How to send reply from expandable notification in

2019-07-20 04:08发布

问题:

Please find below android gmail notification screen which has option of archive and reply. On pressing reply instead of opening gmail app, the edittext should be displayed in notification area which will accept the reply text message and reply message should be sent from notification itself. How we can achive this ? As per the link below we can display set action to archive and reply buttons. http://developer.android.com/training/notify-user/expanded.html

// Sets up the archive and reply action buttons that will appear in the
// big view of the notification.

Intent archiveIntent = new Intent(this, ResultActivity.class);
archiveIntent.setAction(CommonConstants.ACTION_ARCHIVE);
PendingIntent piArchive = PendingIntent.getService(this, 0, archiveIntent, 0);

Intent replyIntent = new Intent(this, ResultActivity.class);
replyIntent.setAction(CommonConstants.ACTION_REPLY);
PendingIntent piReply = PendingIntent.getService(this, 0, replyIntent, 0);


NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_notification)
.setContentTitle(getString(R.string.notification)) .setContentText(getString(R.string.ping))
.setDefaults(Notification.DEFAULT_ALL) 
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.addAction (R.drawable.ic_stat_archive,getString(R.string.archive), piArchive)
.addAction (R.drawable.ic_stat_reply,getString(R.string.reply), piReply);

On pressing reply button instead of going to gmail app/ opening the full page ResultActivity it should display edittext of specified height , width and one reply button in notification area itself. How this can be achieved? Kindly suggest which approach can be followed in order to achieve this. Thanks in advance.

回答1:

This is currently not possible. You have a set number of possible notification types as specified here: http://developer.android.com/guide/topics/ui/notifiers/notifications.html and none of them allow input in the notification drawer. The second best thing you can do is have them click reply and a dialog can open with only the required fields (and not open a whole activity)