我想创建一个通知,单击它时应该打开活动。但是当我点击通知活动时没有打开。这是我的代码:
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(context, MessageReceivedActivity.class);
intent.putExtra("payload", payload);
intent.setAction(Long.toString(System.currentTimeMillis()));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder notification = new Notification.Builder(context)
.setContentTitle("Message Received")
.setSmallIcon(R.drawable.icon)
.setContentText(payload)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
Notification notificationn = notification.getNotification();
notificationManager.notify(0, notificationn);