android – GCM消息被覆盖?

android – GCM消息被覆盖?,第1张

概述大家好我正在使用GCM推送通知向用户传递一些通知.我的问题是当我发送单个消息然后这个工作正常如果发送多个,然后最后一条消息显示给所有通知. 帮我这个,我犯了错误……? private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; l 大家好我正在使用GCM推送通知向用户传递一些通知.我的问题是当我发送单个消息然后这个工作正常如果发送多个,然后最后一条消息显示给所有通知.
帮我这个,我犯了错误……?

private static voID generateNotification(Context context,String message) {  int icon = R.drawable.ic_launcher;  long when = System.currentTimeMillis();  notificationmanager notificationmanager = (notificationmanager)          context.getSystemService(Context.NOTIFICATION_SERVICE);  Intent notificationIntent = new Intent(context,GCMMessageVIEw.class);  String[] messageArray = message.split("\#");  // param :: agentID,name,Msg  DatabaseHelper db = new DatabaseHelper(context);  int notificationID = db.insertnotifications(messageArray[1],messageArray[0],messageArray[messageArray.length-1]);  notificationIntent.putExtra("message",messageArray[messageArray.length-1]);  // set intent so it does not start a new activity  notificationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);  PendingIntent intent = PendingIntent.getActivity(context,notificationIntent,0);  Notification notification = new NotificationCompat.Builder(context)        .setContentText(messageArray[messageArray.length-1])        .setContentTitle(context.getString(R.string.app_name))        .setSmallicon(icon)        .setWhen(when)        .setContentIntent(intent)        .build();    notification.flags |= Notification.FLAG_auto_CANCEL;    // Play default notification sound    notification.defaults |= Notification.DEFAulT_SOUND;    // Vibrate if vibrate is enabled    notification.defaults |= Notification.DEFAulT_VIBRATE;    notificationmanager.notify(notificationID,notification);}
解决方法 为每封邮件设置唯一的通知ID.因此,它被覆盖了. 总结

以上是内存溢出为你收集整理的android – GCM消息被覆盖?全部内容,希望文章能够帮你解决android – GCM消息被覆盖?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1123321.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存