【发布时间】:2014-01-19 19:11:00
【问题描述】:
下面是我的代码块,当点击通知时应该打开NotificationActivity。但它不起作用。
private void setNotification(String notificationMessage) {
Uri alarmSound = getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mNotificationManager = getApplication().getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(getApplicationContext(), NotificationActivity2.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.logo)
.setContentTitle("My Notification")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(notificationMessage))
.setContentText(notificationMessage).setAutoCancel(true);
mBuilder.setSound(alarmSound);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
【问题讨论】:
-
您是否检查了当前时间而不是 NOTIFICATION_ID?
-
你的清单中有
NotificationActivity2吗? -
通过添加系统时间作为 ID 解决。感谢 piyush.. 以及所有其他试图帮助我的人 :)
标签: android android-pendingintent