Android Phonegap GCM 多重通知

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

我正在使用带有 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);      

最佳答案

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

notificationManager.notify(0, notification);

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

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

关于Android Phonegap GCM 多重通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17154609/

相关文章:

php - 将 PHP 用于 iPhone APNS 时出错

android - 如何在 Android SDL2.0 NDK C 上获取屏幕尺寸?

java - Android 我如何在 Thread 上使用 Realm

cordova - jPlayer 和 PhoneGap 构建兼容性

android - 如何使用 Phonegap/Cordova 加密 android 应用程序上的 cookie

xml - Youtube API - 订阅推送通知

ios - 在 APNS 的推送通知中发送摄像头

android - 是否可以从安卓平板电脑截屏到智能板或其他安卓平板电脑

Android Intent 无法解析构造函数

sqlite - Phonegap不支持sql Rand(),该怎么办?