我正在尝试通知回复,比如whatsapp。根据通知操作点击打开不同的活动
这里是我的代码
public void sendNotification(String msg, Intent i, ContactModel contact)
{
i.putExtra("message", msg);
i.putExtra("contact", new Gson().toJson(contact));
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mNotificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
String replyLabel = "Reply";
RemoteInput remoteInput = new RemoteInput.Builder("KEY_REPLY")
.setLabel(replyLabel)
.build();
PendingIntent contentIntent = PendingIntent.getActivity(context, 100, i,
PendingIntent.FLAG_UPDATE_CURRENT);
Bundle bundle = new Bundle();
bundle.putBoolean("reply", true);
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
R.drawable.ic_phone, replyLabel, contentIntent)
.addRemoteInput(remoteInput)
.addExtras(bundle)
.setAllowGeneratedReplies(true)
.build();
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
.setContentTitle(contact.getName())
.setDefaults(Notification.DEFAULT_SOUND)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("Content Hidden"))
.setContentText(msg)
.addAction(replyAction)
;
mBuilder.setContentIntent(contentIntent);
mNotificationManager.cancel(Constants.PUSH_ID);
mNotificationManager.notify(Constants.PUSH_ID, mBuilder.build());
}
现在我的通知显示“消息”和“回复”按钮。
我面临的问题是,我无法区分用户选择回复按钮还是尝试打开通知。
我的主要意图是
Intent myIntent = new Intent(this, NotificationActivity.class);
我要的是, 当“回复”用户点击按钮,它会打开
Intent myIntent = new Intent(this, NotificationActivity.class);
当通知本身就是一个用户点击它打开
Intent myIntent = new Intent(this, MainActivity.class);
即使这是不可能的,我怎么能找出哪个动作是每个形成。
凡定义 “消息” 和 “回复” 按钮? – Cochi
没有消息按钮,只回复和内容消息 –
看看我的文章可以帮助你 – Cochi