开发者社区 问答 正文

【移动推送】Android SDK中调用存在以下问题怎么办?

已解决

为什么调用cloudpushservice.register之后获取deviceId,却发现deviceId为空,这是什么原因造成的?

展开
收起
EMAS支持组 2022-09-15 14:06:45 341 分享 版权
1 条回答
写回答
取消 提交回答
  • 采纳回答

    问题原因

    推送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());
          }
    });
    

    更多官方信息

    EMAS官网介绍:https://www.aliyun.com/product/emas

    Devops:https://www.aliyun.com/product/emascrash/mobile_devops

    移动热修复:https://www.aliyun.com/product/hotfix

    移动测试:https://www.aliyun.com/activity/emas/mqcexpert

    移动推送:https://www.aliyun.com/product/cps

    HTTPDNS:https://www.aliyun.com/product/httpdns

    EMAS 控制台: https://emas.console.aliyun.com/products

    2022-09-15 15:05:54
    赞同 展开评论