[英]How to get registration id of failure push notification on android device using Java GCM API
I have implemented below code in java using GCM API to send notification on Android device. 我已经使用GCM API在Java中实现了以下代码,以在Android设备上发送通知。
Sender sender = new Sender(GCM_API_KEY);
Message.Builder builder = new Message.Builder();
builder.collapseKey(collpaseKey);
builder.timeToLive(TTL_HOURS * 3600);
if (data != null) {
for (PushData messageData : data) {
builder.addData(messageData.getKey(), messageData.getValue());
}
}
if (StreamType.CALL == type) {
for (PushData pushData : message) {
builder.addData(pushData.getKey(), pushData.getValue());
}
}
Message msg = builder.build();
try {
System.out.println(msg.toString());
MulticastResult result = sender.send(msg, pushId, MAX_RETRY);
log.infof("result %s", result.toString());
return true;
}
here pushId is type of List, which contain all device's push id, at which, notification to be sent. 这里pushId是列表的类型,其中包含所有设备的推送ID,在该设备上将发送通知。
Problem is that, result does not contain failure push Id or any device identification so that i can identify which device has not received notification. 问题是,结果不包含故障推送ID或任何设备标识,因此我可以标识哪个设备尚未收到通知。 Note:- I don't want to send notification one by one
注意:-我不想一一发送通知
Response - result 回应-结果
MulticastResult(multicast_id=7588781423174816193,total=5,success=1,failure=4,canonical_ids=0,results: [[ errorCode=NotRegistered ], [ messageId=0:1505731620878025%f02bfbe47eeff668 ], [ errorCode=NotRegistered ], [ errorCode=NotRegistered ], [ errorCode=NotRegistered ]]
MulticastResult(multicast_id = 7588781423174816193,总计= 5,成功= 1,失败= 4,canonical_ids = 0,结果:[[errorCode = NotRegistered],[messageId = 0:1505731620878025%f02bfbe47eeff668],[errorCode = NotRegistered],[errorCode =未注册],[errorCode =未注册]]
which does not contain any registration id or something so that i could identify the device in db. 它不包含任何注册ID或什么,以便我可以在db中识别设备。
Please suggest, Thanks in Advance. 请提出建议,在此先感谢。
The response tells you indirectly with push ids failed. 响应会间接告诉您推送ID失败。
In your example: 在您的示例中:
[[ errorCode=NotRegistered ],
[ messageId=0:1505731620878025%f02bfbe47eeff668 ],
[ errorCode=NotRegistered ],
[ errorCode=NotRegistered ],
[ errorCode=NotRegistered ]]
you can see that the 1st, 3rd, 4th and 5th push IDs failed. 您会看到第1,第3,第4和第5个推送ID失败。 Since you are supposed to know in which order you sent the push IDs in your request, you should know which push IDs failed.
由于您应该知道在请求中按哪个顺序发送了推送ID,因此您应该知道哪个推送ID失败。
Here's a relevant example from the documentation : 这是文档中的一个相关示例:
Here are JSON results for 6 recipients (IDs 4, 8, 15, 16, 23, and 42 respectively) with 3 messages successfully processed, 1 canonical registration token returned, and 3 errors:
以下是6个接收者(分别为ID 4、8、15、16、23和42)的JSON结果,其中3个消息已成功处理,返回了1个规范的注册令牌,以及3个错误:
{ "multicast_id": 216, "success": 3, "failure": 3, "canonical_ids": 1, "results": [
{“ multicast_id”:216,“ success”:3,“ failure”:3,“ canonical_ids”:1,“ results”:[
{ "message_id": "1:0408" },{“ message_id”:“ 1:0408”},
{ "error": "Unavailable" },{“错误”:“不可用”},
{ "error": "InvalidRegistration" },{“ error”:“ InvalidRegistration”},
{ "message_id": "1:1516" },{“ message_id”:“ 1:1516”},
{ "message_id": "1:2342", "registration_id": "32" },{“ message_id”:“ 1:2342”,“ registration_id”:“ 32”},
{ "error": "NotRegistered"} ] }{“ error”:“ NotRegistered”}]}
In this example:
在此示例中:
- First message: success, not required.
第一条消息:成功,不是必需的。
- Second message: should be resent (to registration token 8).
第二条消息:应重新发送(至注册令牌8)。
- Third message: had an unrecoverable error (maybe the value got corrupted in the database).
第三条消息:发生了不可恢复的错误(可能值已在数据库中损坏)。
- Fourth message: success, nothing required.
第四个讯息:成功,什么都不需要。
- Fifth message: success, but the registration token should be updated in the server database (from 23 to 32).
第五条消息:成功,但是注册令牌应该在服务器数据库中更新(从23到32)。
- Sixth message: registration token (42) should be removed from the server database because the application was uninstalled from the device.
第六条消息:应从服务器数据库中删除注册令牌(42),因为已从设备上卸载了应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.