2012-07-13 2 views
2

Google 클라우드 메시징을 사용하여 푸시 알림을 제공하고 있습니다. 10.000 명의 사용자에게 브로드 캐스트 알림을 보내야 할 수도 있습니다. 그러나 멀티 캐스트 메시지에는 1000 개의 등록 ID가있는 목록이 포함될 수 있다고 읽었습니다.Google Cloud Messaging으로 브로드 캐스트 알림 전송

그래서 10 개의 멀티 캐스트 메시지를 보내야합니까? 모든 ID로 목록을 생성하지 않고 모든 클라이언트에게 브로드 캐스트를 보낼 수있는 방법이 있습니까?

감사합니다.

답변

0

브로드 캐스트를 최대 1,000 개의 청크로 분할 할 수밖에 없습니다.

그런 다음 멀티 캐스트 메시지를 별도의 스레드로 보낼 수 있습니다. 플레이 서비스 7.5 이후

 //regIdList max size is 1000 
     MulticastResult multicastResult; 
     try { 
      multicastResult = sender.send(message, regIdList, retryTimes); 
     } catch (IOException e) { 
      logger.error("Error posting messages", e); 
      return; 
     } 
1

, 그것은 주제를 통해이를 달성하기 위해 지금 수도 있습니다 등록 후

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()); 
,451,515,

그리고 당신의 클라이언트/주제/foo는 바에 가입해야합니다 :

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. 
}