【发布时间】:2015-09-22 12:40:07
【问题描述】:
我在互联网上没有找到解决问题的单一解决方案。
int notificationId = Integer.parseInt(Common.getStringSharedPreference(context, "NOTIFICATION_ID", "ID", "1"));
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.app_logo, message, System.currentTimeMillis());
String title = context.getString(R.string.app_name);
Intent notificationIntent = null;
notificationIntent = new Intent(context, MyLawyerActivity.class);
notificationIntent.putExtra(ExtrasKeys.ITEM_OBJECT, (Serializable) object);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent = PendingIntent.getActivity(context, notificationId, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.sound = Settings.System.DEFAULT_NOTIFICATION_URI;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
Common.putStringSharedPreference(context, "NOTIFICATION_ID", "ID", ""+(notificationId+1));
请注意,我正在使用带有棒棒糖的设备进行测试。
【问题讨论】:
-
你应该为每个通知使用不同的 id ...... notificationManager.notify( HERE , notification);
-
谢谢@koutuk,他在您的原始评论前 5 秒提供了答案 :)
标签: android google-cloud-messaging android-notifications android-pendingintent