10

I am using following code snippet, however I still can't get the pushToken.

private void obtainToken() {
    // get token
    new Thread() {
        @Override
        public void run() {
            try {
                String appId = AGConnectServicesConfig.fromContext(MainActivity.this).getString("client/app_id");
                pushtoken = HmsInstanceId.getInstance(MainActivity.this).getToken(appId, "HCM");
                if(!TextUtils.isEmpty(pushtoken)) {
                    Log.i(TAG, "get token:" + pushtoken);
                }
            } catch (Exception e) {
                Log.i(TAG,"getToken failed, " + e);

            }
       }
   }.start();
}
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
Irene Li
  • 101
  • 1
  • 1
  • 3
  • 1
    Please check out the logcat. – deadfish Apr 23 '20 at 18:33
  • 1
    I'm also facing this issue and am getting the following error: ```I/HMSSDK_HmsClient: receive msg status_code:1, error_code907135000, api_name:push.gettoken, app_id:|, pkg_name:com.xxxx.android, session_id:*, transaction_id:000000000ttoken20200521161603156246407, resolution:null I/MainActivity: gettoken failed, com.huawei.hms.common.ApiException: 907135000: arguments invalid ``` – CacheMeOutside May 21 '20 at 14:17
  • @CacheMeOutside you can quite clearly see from the log message that your app_id is not set up correctly in the manifest. – Anders Emil Jun 26 '20 at 14:04

5 Answers5

7

Having a log would be perfect but if everything fine in the logs, no exception and result code from HCM is success, then verify the EMUI version of your device.

If your device's EMUI version is earlier than 10.0, the code you have used will return empty push token. In such case, it is necessary to implement a custom service extending HmsMessageService.

In your AndroidManifest.xml add;

<service
   android:name=".CustomPushService"
   android:exported="false">
      <intent-filter>
         <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
     </intent-filter>
</service>

Then create following class;

public class CustomPushService extends HmsMessageService {
     private static final String TAG = "PushTokenLog";

     @Override
     public void onNewToken(String token) {

       super.onNewToken(token);
       Log.i(TAG, "receive token:" + token);
      }
}

Last but not least, make sure your device is Huawei :) Most of the features of HMS Core relies on EMUI. Without EMUI, functionality of the functions is not guaranteed for now.

Below is a nice reference to see HMS Core - EMUI relation. https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/emui_version_dependent_features

Update as per the comment of question owner

The return code 907135000 means that your SDK configurations are not correct. Take your time to check following points;

  1. Check whether the app_id and package_name parameters in the agconnect-services.json file are correct. The app_id and package name should match the app created on AGC. Also, consider re-downloading corresponding agconnect-service.json
  2. Check whether the certificate signature is configured in the build.gradle file.
  3. The fault may be caused by the cache of HMS Core (APK). Uninstall and then reinstall HMS Core (APK), disconnect and reconnect the phone with the Internet, and start the app again.
captaink
  • 476
  • 3
  • 8
0

You can get a pushToken on the premise that the preparation work has been done, especially enabling the push service and setting up the fingerprint. For details, refer to the following link: App development

You can view the logcat with filter "hmssdk" after checking. If there is an exception, you can see the error code, and then you can refer to the document for how to solve the problem. Here is the link:

Show the log if possible so that we can solve the problem together.

For more details, you can refer to the document about how to get pushToken.

If the EMUI version is 10.0 or later on a Huawei device, a token will be returned through the getToken method. If the getToken method fails to be called, HUAWEI Push Kit automatically caches the token request and calls the method again. A token will then be returned through the onNewToken method. If the EMUI version on a Huawei device is earlier than 10.0 and no token is returned using the getToken method, a token will be returned using the onNewToken method.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
0

Similar issue, getting an error:

GET token failed, com.huawei.hms.common.ApiException: 907122036: no right

Solution:

  • AppGallery Connect
  • Project
  • Push Kit
  • Enable

Done

Jarda Pavlíček
  • 1,636
  • 17
  • 16
  • 2
    Jarda, did you ever get this resolved? I'm getting the same error. According to docs, this error means that Push Kit is not enabled in App Gallery management console, but it is enabled for my app. – Kostya Vasilyev Oct 01 '20 at 13:54
  • I'm getting the same error, but the push kit ie enabled for my project. – Vicky Nov 15 '20 at 03:22
  • i am also getting this error, push notification is enabled. how i can enable the project Receipt and App Receipt because it require Name, callback and Http certificate , so from where i can get these param values – Mudassir Khan Sep 10 '21 at 09:59
0

I got the same error. I fixed the problem. If you work in more than one medium, check the flavor files. Make sure it's correct.

Multiple Flavors Document :

https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-config-flavor

Halil Ozel
  • 2,482
  • 3
  • 17
  • 32
0

Maybe a little bit late, but still.

getToken fails because AGConnectServicesConfig.getString("client/app_id"); returns null, which you pass into getToken method.

In the recent Huawei Services version, to get appId you should ask for /client/app_id, not client/app_id string like this:

String appId = AGConnectServicesConfig.fromContext(MainActivity.this).getString("/client/app_id");

Everything else stays the same. But I would recommend writing if statement to check if appId is null and track that. That will save you time if Huawei decides to change that value again.

  • It's never too late. Saved my day, codelab somehow still supplies `"client/app_id"` – Dmitrii Leonov May 12 '21 at 10:15
  • @dmitrii-leonov I don't know how my solution helped me in the first place (when I was debuging it just worked) because the next day I found out, that `appId` is still `null`. My issue was that we disabled agconnect gradle plugin and config.json didn't get inside application. I have no idea, how that extra '/' helped me, probably that was lucky coincidence. So you should be aware of that your case can be coincidence too. Especially because, as i found out, there is code inside `AGConnectServicesConfig` that adds '/' in the begining of string if required. – Максим Дрозд May 19 '21 at 10:48
  • @МаксимДрозд wow yep those id getters suck, we should probably edit your answer to avoid further confusions. Thanks. – Murciegalo84 Sep 10 '21 at 20:26