【问题标题】:How to do multicast of push notification?如何进行推送通知的多播?
【发布时间】:2014-07-12 15:45:12
【问题描述】:

我可以一次向一台设备发送通知。 我需要更改 php 代码或 java 代码? 以下是我的代码:

创建通知以通知用户服务器已发送消息。

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);

    Intent notificationIntent = new Intent(context, MainActivity.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, 0, 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);      

}

}

【问题讨论】:

    标签: php android push-notification google-cloud-messaging


    【解决方案1】:

    Android 应用上的 Java 代码与发送多播消息无关。您必须更改服务器上的 PHP 代码。

    如果你想向多个设备发送相同的消息,你应该发送一个带有application/json内容类型的HTTP请求:

    {
      "registration_ids" : ["reg-id1","reg-id2",...],
      "data" : {
        ...
      },
    }
    

    这允许您在单个 HTTP 请求中向多达 1000 台设备发送相同的消息。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多