【问题标题】:Android Phonegap GCM Multiple NotificationAndroid Phonegap GCM 多重通知
【发布时间】:2013-06-17 18:48:15
【问题描述】:

我正在使用带有 GCM 插件的 Phonegap 来显示 GCM 通知。 我能够正确显示通知,但无法显示多个通知。我试过Notification passes old Intent Extras,但还没有结果。 请帮忙。

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);
        Notification notification = new Notification(icon, message, when);

        String title = context.getString(R.string.app_name);
        int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);

       // saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
        Intent notificationIntent = new Intent(context, JainDharma.class);
        // set intent so it does not start a new activity
        //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(context, iUniqueId, notificationIntent, 0);
        //PendingIntent contentIntent = PendingIntent.getActivity(context, UNIQUE_INT_PER_CALL, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;

        //notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");

        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);      

【问题讨论】:

  • 请提供有关您的问题的更多详细信息。您是否收到任何错误消息。你试过什么。你试过调试吗?你从中学到了什么?在您尽可能地尝试和研究问题之后,在 StackOverflow 上发布一个新问题应该是您最后的选择。然后在此处提供您在此过程中收集的所有信息。

标签: android cordova push-notification google-cloud-messaging android-notifications


【解决方案1】:

如果您的意思是最后一个通知覆盖了前一个通知,并且您希望更改它,则需要更改以下内容:

notificationManager.notify(0, notification);

为每个通知使用不同的 ID(而不是 0),您将看到所有通知。

但是,您可能需要重新考虑为同一个应用显示多个通知是否是个好主意。作为您应用的用户,我会觉得这很烦人。

【讨论】:

  • 我们不会在同一天推送很多通知。它是每天 1-2 条新闻。无论如何,非常感谢
猜你喜欢
  • 2014-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-05
  • 2015-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多