Why can't I get pushToken by using Huawei Push Kit? - android

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

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;
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
Check whether the certificate signature is configured in the build.gradle file.
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.

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.

Similar issue, getting an error:
GET token failed, com.huawei.hms.common.ApiException: 907122036: no right
Solution:
AppGallery Connect
Project
Push Kit
Enable
Done

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

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.

Related

FCM token is not getting generated in few devices

I am using FirebaseInstanceId.getInstance().getToken() method to generate device token. I know this method is deprecated, but I am keen to find the exact RCA for the issue.
When I am using this method in emulator, it is working fine and returning token with all emulator variation tried with multiple emulators.
I tried debugging with android phone it is returning device token. But Our application runs on Zebra TC57 device and there it is not working and method is returning null.
This works in some device and not works in some device. I have one device where it's not working to reproduce the issue
Android version : 8.1.0
I tried checking Google play Service version with
PackageInfoCompat.getLongVersionCode(getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0 )); this is returning 17785019
I checked for google play store package availability
PackageInfoCompat.getLongVersionCode(getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0 )); this is giving package name `com.android.vending` translating to new GooglePlayStorePackageName.
Tried multiple other steps but not able to find exact root cause
That method is deprecated for a reason. Just use the new recommended method.
FCM does not guarantee the generation of these tokens. But when it does generate the token, you are guaranteed to get the new token in the onNewToken method in your FCM service.
class NotificationService: FirebaseMessagingService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
}
}
excerpt from the documentation
/**
There are two scenarios when onNewToken is called:
When a new token is generated on initial app startup
Whenever an existing token is changed
Under #2, there are three scenarios when the existing token is changed:
A) App is restored to a new device
B) User uninstalls/reinstalls the app
C) User clears app data
*/
You can get the generated token on demand anywhere in your app using the new method. This method will only return the token if the initial generation was successful.
fun tryGetToken() {
FirebaseMessaging.getInstance().getToken().addOnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w(FCM_TAG, "Fetching FCM registration token failed", task.exception)
return#addOnCompleteListener
}
fcmToken = task.result
Log.d(FCM_TAG, "FCM fetch success $fcmToken")
}

HMS SafetyDetect return token timeout-or-duplicate

On some devices with HMS SDK SafetyDetect, captcha returns a token, when checked, the Huawei server responds
{
"error-codes": "timeout-or-duplicate",
"success": false
}
I am sure of the correct implementation of the library, everything works correctly on the part of devices. This problem arose about 2 weeks ago. Perhaps the version of HMS Core somehow affects. Has anyone faced a similar issue in their applications?
versions:
com.huawei.hms:safetydetect:6.1.0.302
com.huawei.agconnect:agcp:1.6.1.300
{
"error-codes": "timeout-or-duplicate",
"success": false
}
If this error code is displayed, the response parameter is invalid, has expired, or has been used.
You need to use the client interface to obtain the responseToken again and invoke the restApi interface again.
For details, kindly check this docs.

Can't create Twilio ChatClient on android

I'm trying to build chat application on Android and I've stuck on a very first step. I can't create ChatClient. According to documentation I should call some method like this:
ChatClient.create(context.getApplicationContext(), token, props, myCallback);
Unfortunately I'm receiving error: "Invalid access token grants", you can check this link for error details.
I've verified what's inside my jwt access token and it seems that everything is OK with grants. I've used https://jwt.io/ debugger to test it and could see the following payload(I've dashed my credentials to show only structure):
{ "iss": "SK####################",
"exp": 1516198358,
"jti": "SK#####################",
"sub": "######################",
"grants": {
"identity": "test.user#mail.com",
"chat": {
"service_sid": "###################",
"endpoint_id": "###################"
}
}
}
I've checked all the values and they seem to be OK, I've also tried to copy this token and pass it to my web(JS) project and was able to sign in without any issues which proves that token itself should be OK.
Any help appreciated, thanks
So the solution was to use correct region setting, because tokens in one region are incompatible with services from another.
Error messages on the service side are being refined to better reflect this case.
please do not use "endpoint_id" in the grants, it has been deprecated and may be throwing off some service validation logic.
If you continue getting this error please contact support.twilio.com and provide adb logs and the token itself (do not paste it here publicly). Also see https://github.com/twilio/twilio-chat-demo-android/blob/master/REPORT_BUGS.md

Unexpected response code 403 for https://www.googleapis.com/games/v1/players/1123xxxxxx11712506520 and other play-services errors

I'm trying to make games API work, with reference to https://github.com/playgameservices/android-samples/blob/master/BaseGameUtils/src/com/google/example/games/basegameutils/BaseGameActivity.java as sample code.
Mine is quite similar, basically I'm trying to connect a game client and receive a negative answer. When trying to manage it with startResolutionForResult() this is what I got:
E/Volley(15638): [1492] il.a: Unexpected response code 403 for https://www.googleapis.com/games/v1/players/112370814111712506xxx
E/Volley(15638): [1492] il.a: Unexpected response code 403 for https://www.googleapis.com/games/v1/players/112370814111712506xxx
E/SignInIntentService(15638): Access Not Configured
[...]
E/LoadSelfFragment(15748): Unable to sign in - application does not have a registered client ID
The last message, "application does not have a registered client ID" made me think to this question...But I don't think my issue is related to app id / client ID as I got it working with same API keys on another machine. I'm pretty sure of SHA1 correctness, too, derived from current machine's debug.keystore.
The issue seems to be related to test address I'm using, the strange thing is that I don't receive always the same reply: using same keys and settings, I sometimes got:
E/SignInIntentService(15638): Access Not Configured
or even:
E/SignInIntentService(15638): Unable to load player
I'm using startResolutionForResult() inside OnConnectionFailedListener, it's showing the log-in screen briefly, but then it crashes with reported errors.
Another strange thing is that onActivityResult() is called, and result code is 10004
A last thing I can't understand is why, after an unsuccessful sign-in, the method onConnectionFailed() is called over and over, looping my app. Relevant code is:
public void initClient() {
GamesClient.Builder gcBuilder = new GamesClient.Builder(this, cb, cf);
gcBuilder.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
//gcBuilder.setScopes(mScopes);
mGamelient = gcBuilder.create();
mSchiacciameleView.setGameClient(gcBuilder.create());
}
OnConnectionFailedListener cf = new OnConnectionFailedListener() {
public void onConnectionFailed(ConnectionResult arg0) {
Log.e("Verme", "CONN FAIL:" + arg0.getErrorCode());
if (arg0.hasResolution()){
PendingIntent pendingIntent = arg0.getResolution();
//startResolutionForResult(SchiacciaMeleGame.this, 66);
try {
arg0.startResolutionForResult(me, ConnectionResult.SIGN_IN_REQUIRED) ;
} catch (SendIntentException e) {
Log.e("Verme", "Err in resolution", e);
}
}else{
Log.e("Verme", "NO RESOLUTION");
}
}
};
I've been messing with these libraries for two days. Frankly, I don't like the way Google is managing this; documentation is still incomplete and run-time behaviour seems a bit inconsistent (the exact same code is working on another machine, SHA1 is correct on both). Maybe it's my fault?
Thank you for replies
In Step 3. Generate an OAuth 2.0 client ID it specifically gives a warning as follows:
Warning: Do not open the Google APIs Console directly and manually
add your Client IDs on that page. Doing so might cause errors when
you send requests to the game services.
So my experience was that you need to follow the guide religiously: Setting Up Google Play Game Services with the Google Play Developer Console

App engine connected Android app

Problem with the new App engine connected android application projects for the google eclipse plugin? This is the "Big Daddy" sample shown at goolge i/o 2011. My sample project compiles and the android app appears to work fine and registers with the server. However when I send a message from the server I get the following: Having issue with sample project. Android appears to work fine and registers with the server and the c2dm server, however I cannot send a message.
Also of note on the server is a c2dmconfig datastore object. It has fields for authToken and c2dmUrl. The authToken has a token, however the c2dmUrl is NULL. I suspect this is where my problem lies, but not sure how to fix it.
Thanks Patrick
I found this question by wondering the same thing, if the c2dmUrl being null is a problem. It would seem that this is not an issue though. If you look at the C2DMConfig (the entity that you are referencing), there is a function called "getC2DMUrl". Here it is:
public String getC2DMUrl() {
if (c2dmUrl == null) {
return DATAMESSAGING_SEND_ENDPOINT;
} else {
return c2dmUrl;
}
So null is a supported value for this. If a specific URL isn't specified, it simply returns it to the default.

Categories

Resources