华为推送服务:在华为手机上Token返回为空

9

我最近在一台华为手机上测试了我的应用程序。

问题是PushKit没有返回令牌,getToken的结果为空。

在日志中,我得到了GetTokenTask receive a empty token, please check HmsMessageService.onNewToken receive result.的信息,但onNewToken中也没有给出任何令牌。

检索令牌的代码:

GlobalScope.launch(context = Dispatchers.IO) {
    try {
        val appId = AGConnectServicesConfig.fromContext(this@MainActivity).getString("client/app_id")
        val token = HmsInstanceId.getInstance(this@MainActivity).getToken(appId, "HCM")
        Pulp.debug("Huawei", "Token received") {
            "token" to token
        }
    } catch (e: java.lang.Exception) {
        Pulp.error("Huawei", "Failed to fetch token", e) {
            "Cause" to (e.message ?: "Empty")
        }
    }
}

执行结果没有异常,但令牌为空(请参见日志的最后一行)。

HMSService中的代码:

override fun onNewToken(token: String?) {
    super.onNewToken(token)
    Pulp.debug("Huawei", "(onNewToken): Huawei messaging token received") {
        "Token" to (token ?: "NO token")
    }
}

auto_init 到令牌请求的完整日志:

2020-09-16 15:33:50.791 19954-19954/ir.malv.plusdependencytest I/HMSSDK_AutoInit: Push init start
2020-09-16 15:33:50.854 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HMSBIInitializer: Builder->biInitFlag :false
2020-09-16 15:33:50.856 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HMSBIInitializer: Builder->biSetting :false
2020-09-16 15:33:50.859 19954-19954/ir.malv.plusdependencytest I/HMSSDK_CountryCodeBean: getCountryCode get country code from SIM_COUNTRY
2020-09-16 15:33:50.863 19954-19954/ir.malv.plusdependencytest W/HMSSDK_CountryCodeBean: countryCode from system language is not reliable.
2020-09-16 15:33:50.864 19954-19954/ir.malv.plusdependencytest E/HMSSDK_HMSBIInitializer: Failed to get device issue country
2020-09-16 15:33:50.909 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HMSPackageManager: Succeed to find HMS apk: com.huawei.hwid version: 40100308
2020-09-16 15:33:50.934 19954-20000/ir.malv.plusdependencytest I/HMSSDK_HMSBIInitializer: Builder->biInitFlag :false
2020-09-16 15:33:50.936 19954-20000/ir.malv.plusdependencytest I/HMSSDK_HMSBIInitializer: Builder->biSetting :false
2020-09-16 15:33:50.936 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HMSBIInitializer: Builder->biInitFlag :false
2020-09-16 15:33:50.937 19954-20000/ir.malv.plusdependencytest I/HMSSDK_CountryCodeBean: getCountryCode get country code from SIM_COUNTRY
2020-09-16 15:33:50.938 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HMSBIInitializer: Builder->biSetting :false
2020-09-16 15:33:50.939 19954-20000/ir.malv.plusdependencytest W/HMSSDK_CountryCodeBean: countryCode from system language is not reliable.
2020-09-16 15:33:50.940 19954-20000/ir.malv.plusdependencytest E/HMSSDK_HMSBIInitializer: Failed to get device issue country
2020-09-16 15:33:50.953 19954-20000/ir.malv.plusdependencytest I/HMSSDK_HiAnalyticsUtils: issueCountry initial
2020-09-16 15:33:50.953 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HiAnalyticsUtils: issueCountry initial
2020-09-16 15:33:50.954 19954-20000/ir.malv.plusdependencytest I/HMSSDK_CountryCodeBean: getCountryCode get country code from SIM_COUNTRY
2020-09-16 15:33:50.954 19954-19954/ir.malv.plusdependencytest I/HMSSDK_CountryCodeBean: getCountryCode get country code from SIM_COUNTRY
2020-09-16 15:33:50.956 19954-19954/ir.malv.plusdependencytest W/HMSSDK_CountryCodeBean: countryCode from system language is not reliable.
2020-09-16 15:33:50.956 19954-20000/ir.malv.plusdependencytest W/HMSSDK_CountryCodeBean: countryCode from system language is not reliable.
2020-09-16 15:33:50.956 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HiAnalyticsUtils: not ChinaROM
2020-09-16 15:33:50.956 19954-20000/ir.malv.plusdependencytest I/HMSSDK_HiAnalyticsUtils: not ChinaROM
2020-09-16 15:33:50.959 19954-20000/ir.malv.plusdependencytest I/HMSSDK_HiAnalyticsUtils: hw_app_analytics_state value is 0
2020-09-16 15:33:50.959 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HiAnalyticsUtils: hw_app_analytics_state value is 0
2020-09-16 15:33:50.960 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HmsMessaging: invoke turnOnPush
2020-09-16 15:33:50.963 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HmsMessaging: turn on/off with AIDL
2020-09-16 15:33:50.970 19954-20004/ir.malv.plusdependencytest I/HMSSDK_HuaweiApiManager: sendRequest
2020-09-16 15:33:50.971 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: ====== HMSSDK version: 50000301 ======
2020-09-16 15:33:50.972 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: Enter connect, Connection Status: 1
2020-09-16 15:33:50.973 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: connect minVersion:30000000
2020-09-16 15:33:50.975 19954-20004/ir.malv.plusdependencytest I/HMSSDK_Util: available exist: true
2020-09-16 15:33:50.976 19954-20004/ir.malv.plusdependencytest E/HMSSDK_Util: In isAvailableLibExist, Failed to read meta data for the availableLoaded.
2020-09-16 15:33:50.977 19954-20004/ir.malv.plusdependencytest I/HMSSDK_Util: available exist: true
2020-09-16 15:33:50.981 19954-20004/ir.malv.plusdependencytest I/HMSSDK_HMSPackageManager: current versionCode:40100308, minimum version requirements: 30000000
2020-09-16 15:33:50.986 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: check available result: 0
2020-09-16 15:33:50.987 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: enter bindCoreService
2020-09-16 15:33:51.007 19954-20004/ir.malv.plusdependencytest I/HMSSDK_HuaweiApiManager: sendRequest
2020-09-16 15:33:51.008 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: ====== HMSSDK version: 50000301 ======
2020-09-16 15:33:51.009 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: Enter connect, Connection Status: 1
2020-09-16 15:33:51.010 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: connect minVersion:30000000
2020-09-16 15:33:51.010 19954-20004/ir.malv.plusdependencytest I/HMSSDK_Util: available exist: true
2020-09-16 15:33:51.013 19954-20004/ir.malv.plusdependencytest I/HMSSDK_HMSPackageManager: current versionCode:40100308, minimum version requirements: 30000000
2020-09-16 15:33:51.016 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: check available result: 0
2020-09-16 15:33:51.017 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: enter bindCoreService
2020-09-16 15:33:51.681 19954-19954/ir.malv.plusdependencytest I/HMSSDK_BinderAdapter: Enter onServiceConnected.
2020-09-16 15:33:51.682 19954-19954/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: Enter onServiceConnected.
2020-09-16 15:33:51.684 19954-19954/ir.malv.plusdependencytest I/HMSSDK_BinderAdapter: Enter onServiceConnected.
2020-09-16 15:33:51.684 19954-20004/ir.malv.plusdependencytest I/HMSSDK_HmsClient: post msg api_name:push.setNotifyFlag, app_id:102760085|, pkg_name:ir.malv.plusdependencytest, sdk_version:50000301, session_id:*, transaction_id:102760085fyFlag20200916153350948378003, kitSdkVersion:50002300, apiLevel:1
2020-09-16 15:33:51.685 19954-19954/ir.malv.plusdependencytest I/HMSSDK_BaseHmsClient: Enter onServiceConnected.
2020-09-16 15:33:51.689 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseAdapter: in baseRequest + uri is :push.setNotifyFlag, transactionId is : 102760085fyFlag20200916153350948378003
2020-09-16 15:33:51.692 19954-20004/ir.malv.plusdependencytest I/HMSSDK_PendingResultImpl: init uri:push.setNotifyFlag
2020-09-16 15:33:51.694 19954-20004/ir.malv.plusdependencytest I/HMSSDK_PendingResultImpl: setResultCallback
2020-09-16 15:33:51.698 19954-20004/ir.malv.plusdependencytest I/HMSSDK_HmsClient: post msg api_name:push.gettoken, app_id:102760085|, pkg_name:ir.malv.plusdependencytest, sdk_version:50000301, session_id:*, transaction_id:102760085ttoken20200916153350948306787, kitSdkVersion:50002300, apiLevel:1
2020-09-16 15:33:51.706 19954-20004/ir.malv.plusdependencytest I/HMSSDK_BaseAdapter: in baseRequest + uri is :push.gettoken, transactionId is : 102760085ttoken20200916153350948306787
2020-09-16 15:33:51.708 19954-20004/ir.malv.plusdependencytest I/HMSSDK_PendingResultImpl: init uri:push.gettoken
2020-09-16 15:33:51.709 19954-20004/ir.malv.plusdependencytest I/HMSSDK_PendingResultImpl: setResultCallback
2020-09-16 15:33:51.720 19954-19972/ir.malv.plusdependencytest I/HMSSDK_PendingResultImpl: setResult:0
2020-09-16 15:33:51.745 19954-19954/ir.malv.plusdependencytest I/HMSSDK_BaseAdapter: baseCallBack.onComplete
2020-09-16 15:33:51.746 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HmsClient: receive msg status_code:0, error_code0, api_name:push.setNotifyFlag, app_id:102760085|, pkg_name:ir.malv.plusdependencytest, session_id:*, transaction_id:102760085fyFlag20200916153350948378003, resolution:null
2020-09-16 15:33:51.748 19954-19954/ir.malv.plusdependencytest I/HMSSDK_BaseVoidTask: Operate succeed
2020-09-16 15:33:51.771 19954-19972/ir.malv.plusdependencytest I/HMSSDK_PendingResultImpl: setResult:0
2020-09-16 15:33:51.837 19954-19954/ir.malv.plusdependencytest I/HMSSDK_BaseAdapter: baseCallBack.onComplete
2020-09-16 15:33:51.839 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HmsClient: receive msg status_code:0, error_code0, api_name:push.gettoken, app_id:102760085|, pkg_name:ir.malv.plusdependencytest, session_id:*, transaction_id:102760085ttoken20200916153350948306787, resolution:null
2020-09-16 15:33:51.842 19954-19954/ir.malv.plusdependencytest I/HMSSDK_HmsInstanceId: GetTokenTask receive a empty token, please check HmsMessageService.onNewToken receive result.

标记为 pushlog 的日志:

2020-09-16 20:15:10.585 7731-24998/? I/PushLog40100308_HMS: [Core-GWTask-84-859]enter set self show message control flag, req:{"enable":true,"packageName":"ir.malv.plusdependencytest"}(:289)
2020-09-16 20:15:10.586 7731-24998/? I/PushLog40100308_HMS: [Core-GWTask-84-859]init uri:pushcore.enableNotify(:289)
2020-09-16 20:15:10.586 7731-24998/? I/PushLog40100308_HMS: [Core-GWTask-84-859]await(:289)
2020-09-16 20:15:10.586 7731-24998/? I/PushLog40100308_HMS: [Core-GWTask-84-859]awaitOnAnyThread timeout:10 unit:SECONDS(:289)
2020-09-16 20:15:10.588 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Request, URI: pushcore.enableNotify, clientId: {packageName: com.huawei.hwid, sdkVersion: 10000000, originPackageName: ir.malv.plusdependencytest, originAppId: 102760085, originHostAppId: 102760085, originSdkVersion: 50000301}
2020-09-16 20:15:10.588 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]enter enable notify request:EnableNotifyReq{packageName='ir.malv.plusdependencytest', enable=true}
2020-09-16 20:15:10.590 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Response, uri: pushcore.enableNotify, statusCode: 0
2020-09-16 20:15:10.591 7731-24999/? I/PushLog40100308_HMS: [Core-GWTask-85-860]enter get token request:com.huawei.hms.support.api.entity.push.TokenReq{ pkgName: ir.malv.plusdependencytest isFirstTime: true scope: null appId: null} , transactionId:102760085ttoken20200916201509611018781(:289)
2020-09-16 20:15:10.592 7731-19020/? I/PushLog40100308_HMS: [Binder:7731_7-784]setResult:0(:289)
2020-09-16 20:15:10.592 7731-24999/? I/PushLog40100308_HMS: [Core-GWTask-85-860]init uri:pushcore.gettoken(:289)
2020-09-16 20:15:10.593 7731-24999/? I/PushLog40100308_HMS: [Core-GWTask-85-860]await(:289)
2020-09-16 20:15:10.593 7731-24999/? I/PushLog40100308_HMS: [Core-GWTask-85-860]awaitOnAnyThread timeout:10 unit:SECONDS(:289)
2020-09-16 20:15:10.595 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Request, URI: pushcore.gettoken, clientId: {packageName: com.huawei.hwid, sdkVersion: 10000000, originPackageName: ir.malv.plusdependencytest, originAppId: 102760085, originHostAppId: 102760085, originSdkVersion: 50000301}
2020-09-16 20:15:10.595 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]GetTokenRequest: com.huawei.android.pushagent.core.support.entity.TokenReq{ pkgName: ir.malv.plusdependencytest},userId:0,transactionId:102760085ttoken20200916201509611018781
2020-09-16 20:15:10.596 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]check push connection is not exist, reconnect it.
2020-09-16 20:15:10.599 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]dispatchIntent over
2020-09-16 20:15:10.599 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]TRS exceed valid time, so need to query TRS again
2020-09-16 20:15:10.600 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]com.huawei.action.CONNECT_PUSHSRV alarm trigger, expectTriggerTime:0, current trigger time:1600271110600
2020-09-16 20:15:10.602 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]connect srv: TRS is invalid, so need to query TRS
2020-09-16 20:15:10.604 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:10.613 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:10.613 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]begin to get token from pushSrv, pkgName : ir.malv.plusdependencytest, userId :00
2020-09-16 20:15:10.617 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]apply token: TRS is invalid, so need to query TRS
2020-09-16 20:15:10.624 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:10.630 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Response, uri: pushcore.gettoken, statusCode: 0
2020-09-16 20:15:10.632 7731-19020/? I/PushLog40100308_HMS: [Binder:7731_7-784]setResult:0(:289)
2020-09-16 20:15:10.636 7731-24999/? I/PushLog40100308_HMS: [Core-GWTask-85-860]request token for HMS from system push.(:289)
2020-09-16 20:15:10.640 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]request token for HMS by AIDL.(:289)
2020-09-16 20:15:10.641 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]init uri:pushcore.gettoken(:289)
2020-09-16 20:15:10.642 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]await(:289)
2020-09-16 20:15:10.642 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]awaitOnAnyThread timeout:10 unit:SECONDS(:289)
2020-09-16 20:15:10.644 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Request, URI: pushcore.gettoken, clientId: {packageName: com.huawei.hwid, sdkVersion: 10000000, originPackageName: ir.malv.plusdependencytest, originAppId: 102760085, originHostAppId: 102760085, originSdkVersion: 50000301}
2020-09-16 20:15:10.644 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]GetTokenRequest: com.huawei.android.pushagent.core.support.entity.TokenReq{ pkgName: com.huawei.hwid},userId:0,transactionId:102760085ttoken20200916201509611018781
2020-09-16 20:15:10.645 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]check push connection is not exist, reconnect it.
2020-09-16 20:15:10.647 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]dispatchIntent over
2020-09-16 20:15:10.647 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]TRS exceed valid time, so need to query TRS again
2020-09-16 20:15:10.648 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]com.huawei.action.CONNECT_PUSHSRV alarm trigger, expectTriggerTime:0, current trigger time:1600271110648
2020-09-16 20:15:10.653 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]connect srv: TRS is invalid, so need to query TRS
2020-09-16 20:15:10.657 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:10.657 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:10.664 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]begin to get token from pushSrv, pkgName : com.huawei.hwid, userId :00
2020-09-16 20:15:10.667 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]apply token: TRS is invalid, so need to query TRS
    Tags: [Huawei]
    Message: Succefully turned on Push
2020-09-16 20:15:10.675 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:10.678 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Response, uri: pushcore.gettoken, statusCode: 0
2020-09-16 20:15:10.679 7731-8371/? I/PushLog40100308_HMS: [Binder:7731_6-640]setResult:0(:289)
2020-09-16 20:15:23.427 7731-25033/? I/PushLog40100308_HMS: [Core-GWTask-86-862]enter get token request:com.huawei.hms.support.api.entity.push.TokenReq{ pkgName: ir.malv.plusdependencytest isFirstTime: false scope: null appId: null} , transactionId:102760085ttoken20200916201523364702182(:289)
2020-09-16 20:15:23.428 7731-25033/? I/PushLog40100308_HMS: [Core-GWTask-86-862]init uri:pushcore.gettoken(:289)
2020-09-16 20:15:23.429 7731-25033/? I/PushLog40100308_HMS: [Core-GWTask-86-862]await(:289)
2020-09-16 20:15:23.429 7731-25033/? I/PushLog40100308_HMS: [Core-GWTask-86-862]awaitOnAnyThread timeout:10 unit:SECONDS(:289)
2020-09-16 20:15:23.432 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Request, URI: pushcore.gettoken, clientId: {packageName: com.huawei.hwid, sdkVersion: 10000000, originPackageName: ir.malv.plusdependencytest, originAppId: 102760085, originHostAppId: 102760085, originSdkVersion: 50000301}
2020-09-16 20:15:23.433 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]GetTokenRequest: com.huawei.android.pushagent.core.support.entity.TokenReq{ pkgName: ir.malv.plusdependencytest},userId:0,transactionId:102760085ttoken20200916201523364702182
2020-09-16 20:15:23.433 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]check push connection is not exist, reconnect it.
2020-09-16 20:15:23.436 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]dispatchIntent over
2020-09-16 20:15:23.436 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]TRS exceed valid time, so need to query TRS again
2020-09-16 20:15:23.437 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]com.huawei.action.CONNECT_PUSHSRV alarm trigger, expectTriggerTime:0, current trigger time:1600271123437
2020-09-16 20:15:23.439 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]connect srv: TRS is invalid, so need to query TRS
2020-09-16 20:15:23.443 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:23.444 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:23.449 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]begin to get token from pushSrv, pkgName : ir.malv.plusdependencytest, userId :00
2020-09-16 20:15:23.453 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]apply token: TRS is invalid, so need to query TRS
2020-09-16 20:15:23.458 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:23.462 6359-25001/? I/PushLog100101302: [IO-pool-thread-35-1642]Response, uri: pushcore.gettoken, statusCode: 0
2020-09-16 20:15:23.462 7731-8371/? I/PushLog40100308_HMS: [Binder:7731_6-640]setResult:0(:289)
2020-09-16 20:15:23.465 7731-25033/? I/PushLog40100308_HMS: [Core-GWTask-86-862]request token for HMS from system push.(:289)
2020-09-16 20:15:23.465 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]request token for HMS by AIDL.(:289)
2020-09-16 20:15:23.466 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]init uri:pushcore.gettoken(:289)
2020-09-16 20:15:23.466 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]await(:289)
2020-09-16 20:15:23.466 7731-14337/? I/PushLog40100308_HMS: [Push-Task-1-717]awaitOnAnyThread timeout:10 unit:SECONDS(:289)
2020-09-16 20:15:23.469 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Request, URI: pushcore.gettoken, clientId: {packageName: com.huawei.hwid, sdkVersion: 10000000, originPackageName: ir.malv.plusdependencytest, originAppId: 102760085, originHostAppId: 102760085, originSdkVersion: 50000301}
2020-09-16 20:15:23.470 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]GetTokenRequest: com.huawei.android.pushagent.core.support.entity.TokenReq{ pkgName: com.huawei.hwid},userId:0,transactionId:102760085ttoken20200916201523364702182
2020-09-16 20:15:23.471 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]check push connection is not exist, reconnect it.
2020-09-16 20:15:23.474 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]dispatchIntent over
2020-09-16 20:15:23.474 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]TRS exceed valid time, so need to query TRS again
2020-09-16 20:15:23.476 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]com.huawei.action.CONNECT_PUSHSRV alarm trigger, expectTriggerTime:0, current trigger time:1600271123476
2020-09-16 20:15:23.480 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:23.481 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]connect srv: TRS is invalid, so need to query TRS
2020-09-16 20:15:23.487 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]begin to get token from pushSrv, pkgName : com.huawei.hwid, userId :00
2020-09-16 20:15:23.491 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]apply token: TRS is invalid, so need to query TRS
2020-09-16 20:15:23.492 6359-6417/? I/PushLog100101302: [ReceiverDispatcher-383]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:23.500 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Not allow to use push in this area, and not pass interval,result code: 26, belong id is -1, server ip is , region of TRS server is -1
2020-09-16 20:15:23.503 6359-25003/? I/PushLog100101302: [IO-pool-thread-36-1644]Response, uri: pushcore.gettoken, statusCode: 0
2020-09-16 20:15:23.504 7731-8371/? I/PushLog40100308_HMS: [Binder:7731_6-640]setResult:0(:289)


关于手机和应用程序的信息:

  • 手机型号:Huawei Y7p
  • Android版本:10
  • EMUI版本:10.1.0
  • AGConnect版本:'com.huawei.agconnect:agcp:1.4.1.300'
  • PushKit版本:"com.huawei.hms:push:5.0.2.300"
  • AGConnect-Core版本:"com.huawei.agconnect:agconnect-core:1.4.1.300"
  • 自动初始化:
<meta-data
     android:name="push_kit_auto_init_enabled"
     android:value="true" />
  • HMS服务:
<service
    android:name=".services.HmsService"
    android:exported="false">
     <intent-filter>
         <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
     </intent-filter>
</service>

一些其他信息:

  • 相同的应用程序可以在带有HMS Core v5.0.0.304Samsung G-A40上获取HMS令牌。
  • 没有将帐户与应用商店同步,设备是全新的。
  • 地区(国家和IP):伊朗

需要额外的信息:

  • 从0开始记录Galaxy A40日志并发送上行 [链接]
  • 允许HMS核心Phone权限的Galaxy A40日志 链接

嗨!只是想确认一下,你是否实现了与 https://developer.huawei.com/consumer/en/doc/HMSCore-Guides-V5/android-client-dev-0000001050042041-V5 相同的 getToken() 方法?如果是,请在 AndroidManifest.xml 中注释掉 push_kit_auto_init_enabled 并再次尝试。 - clho
@clho 我更新了问题,并附上了我尝试获取令牌的代码。我删除了应用程序数据并重新尝试,没有使用 auto_init 标签。但仍然收到空令牌。 - Mahdi-Malv
我已经尝试了你的getToken方法,它对我有效。你能否也展示一下你的onNewToken方法?(另外,只是想确认一下,你是否在AppGallery Connect上启用了推送服务?) - clho
@clho 已完成。但是它甚至没有被调用。与此同时,我能够在非华为 HMS-Core 包含的手机上获取令牌。 - Mahdi-Malv
1
@Mahdi-Malv,请提供三星G-A40的日志记录。 :) - zhangxaochen
显示剩余7条评论
2个回答

2
混合使用自动初始化参数 push_kit_auto_init_enabled 和手动获取方法 getToken() 将会导致问题。
我们遇到了类似的问题,有时会收到令牌,有时则不会。这似乎很随机,但基本规则是您应该使用此处描述的自动方法之一,或者您可以遵循部分的说明,在完成所有配置(第1部分第2部分第3部分第4部分)后立即申请令牌。
这应该解决在允许推送消息的国家中遇到此问题的任何其他人的问题。

很抱歉,根据您的解决方案,我无法解决它。感谢您的回复。 - Mahdi-Malv
1
是的,我看到了,这可能与你的国家尚未支持推送工具有关。但是,如果有人遇到了这个问题并在Stackoverflow上看到了你的问题,他/她就不必尝试我们所做的所有不同方法来找出解决方案 :) - devEnju

0
  1. 目前 Push Kit 不支持伊朗。
  2. 请检查您的 Samsung Galaxy A40 是否插入了 SIM 卡。Push Kit 将根据条件确定您的服务区域。如果可以,请报告 SIM 卡的 MCC/MNC 和网络区域,以便最初使用 Push Kit。根据日志,Samsung Galaxy A40 的服务区域为欧洲。因此,您可以获取令牌。

要解决 @Angelo 无法获取令牌的问题,请按照以下步骤进行:

只有在准备工作完成,特别是启用推送服务和设置指纹后,才能获取 pushToken。有关详细信息,请参阅以下链接:应用程序开发

检查后,您可以使用过滤器“hmssdk”查看logcat。如果有异常,您可以看到错误代码,然后可以参考文档来解决问题。

如有可能,请展示日志以便我们一起解决问题。

有关如何获取pushToken的详细信息,请参阅文档。

如果华为设备上的EMUI版本为10.0或更高版本,则将通过getToken方法返回令牌。如果无法调用getToken方法,则HUAWEI Push Kit会自动缓存令牌请求并再次调用该方法。然后将通过onNewToken方法返回令牌。如果华为设备上的EMUI版本早于10.0且未使用getToken方法返回令牌,则将使用onNewToken方法返回令牌。


很抱歉,与“伊朗不支持”相关的链接并不是指支持用户接收推送。这会导致用户完全无法接收推送通知。创建应用程序时,我选择了欧洲作为地区来指定服务器位置(由于伊朗不在列表中,我放弃了快速响应并选择了最近的地区)。此外,我的A40手机和华为手机一样,都拥有同样的位置和功能,配备了伊朗SIM卡。我相信问题不在于缺乏支持。顺便问一下,“get grs failed,the errorcode is -5”是什么意思?没有关于“-5”的描述。 - Mahdi-Malv
@bigface 这里可以查看日志:日志代码片段 - Mahdi-Malv
是的,我也指的是三星A40。您能否分享带有标签“pushlog”和您的HMS Core版本的日志? - bigface
@bigface 这里是更新后的日志(https://gist.github.com/mahdi-malv/39d88c20e16860f771d0d93f8623b207)。HMSCore (v5.0.2.300)。检查PushLog标签,可以看到一条有效的信息:“不允许在此区域使用推送,并且未通过间隔,结果代码:26”。这是否意味着“Pushkit在伊朗不受支持”是正确的? - Mahdi-Malv
@Mahdi-Malv 很好。虽然它还没有被添加到文档中。 :) - zhangxaochen
显示剩余7条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接