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();
}
HUAWEI Push Service serves as a platform for app developers to send new messages in real time from the cloud to a terminal device, improving user awareness and engagement.
Automatic Initialization The HMS Core Push SDK provides the capability of automatically generating AAIDs and automatically applying for tokens. You can enable or disable automatic initialization by calling Push.
A push token may change in some scenarios, including but not limited to the following: App data is cleared (when the app is uninstalled, when the device is restored to its factory settings, or in other scenarios), and the app is reinstalled and launched.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With