问题详述
为什么调用cloudpushservice.register之后获取deviceId,却发现deviceId为空,这是什么原因造成的?
问题原因
推送SDK在注册的过程中需要将设备相关信息(appKey,appSecret,包名,设备号等)上报服务端,只有上报成功后服务端才会下发deviceId。如果发现deviceId为空,可能有两个原因:
- 推送初始化失败,此时可通过onFailed回调查看相关错误信息。
- 初始化未完成,推送初始化存在异步操作,在初始化未完成时是无法获取到deviceId的。
解决方案
在CloudPushService.register的成功回调中获取deviceId,请参考下述代码:
pushService.register(applicationContext, new CommonCallback() {
@Override
public void onSuccess(String response) {
Log.i(TAG, "init CloudPushService success, device id: " + pushService.getDeviceId() +", Appkey: " + AmsGlobalHolder.getAppMetaData("com.alibaba.app.appkey"));
}
@Override
public void onFailed(String errorCode, String errorMessage) {
Log.d(TAG, "init CloudPushService failed. errorcode: " + errorCode + ", errorMessage: " + errorMessage + ", deviceId:" + pushService.getDeviceId());
}
});
反馈
- 本页导读 (0)
文档反馈