我正在使用 GCMIntentService 在我的应用程序中处理推送通知。我正在创建一个状态栏通知并使用挂起的 Intent 导航到一个 Activity 。
我创建通知的代码是:
private static void generateNotification(Context context, String message, String title1, String desc, String soln, String date, String time) {
int icon = R.drawable.notification_icon;
long when = System.currentTimeMillis();
Log.i("","@@##@@ notificatin"+title1+desc+soln+message);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context,AppLog.class);
notificationIntent.putExtra(Description.REQUEST_FROM, "notification");
notificationIntent.putExtra(Description.INFO_TITLE, title1);
notificationIntent.putExtra(Description.INFO_DESC, desc);
notificationIntent.putExtra(Description.INFO_SOLUTION, soln);
notificationIntent.putExtra(Description.INFO_DATE, date);
notificationIntent.putExtra(Description.INFO_TIME, time);
PendingIntent pIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, pIntent);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.sound=uri;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
在我的 AppLog.class 中,我的处理方式如下:
if(bundle!=null && bundle.containsKey(Description.REQUEST_FROM)){
Log.i("","@@##@@ applog"+bundle);
}
当第一个通知发送到设备时,数据将正确填充到我的 AppLog Activity 类中。但是对于所有通知,它总是向我显示旧包。
我尝试了所有方法,但问题仍然存在。从服务创建的待定 Intent 或通知是否有任何问题?
最佳答案
这行得通
PendingIntent pIntent = PendingIntent.getActivity(context, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
关于android - Bundle 数据未在从服务中的通知传递的 Activity 中更新,始终填充第一个 bundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19300002/