3

Google Cloud Messaging を使用してプッシュ通知を提供しています。約 10,000 人のユーザーにブロードキャスト通知を送信する必要があるかもしれません。ただし、マルチキャスト メッセージには、最大 1000 の登録 ID を持つリストを含めることができると読みました。

では、10 個のマルチキャスト メッセージを送信する必要がありますか? すべての ID を含むリストを生成せずに、すべてのクライアントにブロードキャストを送信する方法はありますか?

よろしくお願いします。

4

2 に答える 2

1

Play サービス 7.5 以降、トピックを通じてこれを達成することも可能になりました。

https://developers.google.com/cloud-messaging/topic-messaging

登録後、HTTP 経由で GCM サーバーにメッセージを送信する必要があります。

https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
  "to": "/topics/foo-bar",
  "data": {
  "message": "This is a GCM Topic Message!",
  }
}

例えば:

JSONObject jGcmData = new JSONObject();
JSONObject jData = new JSONObject();
jData.put("message", "This is a GCM Topic Message!");
// Where to send GCM message.
jGcmData.put("to", "/topics/foo-bar");

// What to send in GCM message.
jGcmData.put("data", jData);

// Create connection to send GCM Message request.
URL url = new URL("https://android.googleapis.com/gcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "key=" + API_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
conn.setDoOutput(true);

// Send GCM message content.
OutputStream outputStream = conn.getOutputStream();
outputStream.write(jGcmData.toString().getBytes());

クライアントは /topics/foo-bar にサブスクライブする必要があります:

public void subscribe() {
   GcmPubSub pubSub = GcmPubSub.getInstance(this);
   pubSub.subscribe(token, "/topics/foo-bar", null);
}

@Override
public void onMessageReceived(String from, Bundle data) {
   String message = data.getString("message");
   Log.d(TAG, "From: " + from);
   Log.d(TAG, "Message: " + message);
   // Handle received message here.
}
于 2015-09-15T15:26:44.003 に答える
0

ブロードキャストを最大 1000 regId のチャンクに分割するしかありません。

その後、マルチキャスト メッセージを別のスレッドで送信できます。

        //regIdList max size is 1000
        MulticastResult multicastResult;
        try {
            multicastResult = sender.send(message, regIdList, retryTimes);
        } catch (IOException e) {
            logger.error("Error posting messages", e);
            return;
        }
于 2012-10-11T15:47:38.350 に答える