如何在用户点击通知时启动活动?我试过插入一个意图,但它没有做任何事情 -
// **non cleareble notification**//
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti = new Notification.Builder(this)
.setAutoCancel(false)
.setContentIntent(
PendingIntent.getActivity(this, 0, getIntent(),
PendingIntent.FLAG_UPDATE_CURRENT))
.setContentTitle("HELLO world")
.setContentText("PLEASE CHECK WE HAVE UPDATED NEWS")
.setDefaults(Notification.DEFAULT_ALL).setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("ticker message")
.setWhen(System.currentTimeMillis()).build();
noti.flags |= Notification.FLAG_NO_CLEAR;
notificationManager.notify(0, noti);
Intent intent = new Intent(this, NotificationAction.class);
答案 0 :(得分:1)
请勿使用Notification.Builder
,而是使用NotificationCompat.Builder
。
Intent intent = new Intent(this, NewActivity.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
然后在你的建设者中:
mBuilder.setContentIntent(pendingIntent);