Gau*_*wal 1 android google-cloud-messaging
我正在尝试使用此处所述的Google GCM Multicast Messaging .我需要同时发送50,000条消息.
文档说我应该将注册ID列表传递给Sender.send().
我的问题 我很困惑,我是否应该一次通过所有50,000个ID或1000个ID的列表,因为文档说"GCM中最有用的功能之一是支持单个邮件最多1,000个收件人."
[编辑1]这样可以吗?
Sender sender = new Sender(API_KEY);
List<List<String>> regIdsParts = regIdInThousands(getRegistrationIds(), 1000);
for (int i = 0; i < regIdsParts.size(); i++) {
Message message = new Message.Builder()
.addData(MsgKey, message).build();
MulticastResult result = sender.send(message, regIdsParts.get(i), 5);
}
public List<List<String>> regIdInThousands(List<String> list, final int L) {
List<List<String>> parts = new ArrayList<List<String>>();
final int N = list.size();
for (int i = 0; i < N; i += L) {
parts.add(new ArrayList<String>(
list.subList(i, Math.min(N, i + L))));
}
return parts;
}
Run Code Online (Sandbox Code Playgroud)
从方法regIdsThousands 这个问题,谢谢polygenelubricants
| 归档时间: |
|
| 查看次数: |
3706 次 |
| 最近记录: |