Play services version issue for SMS Retriever Api - android

I have already integrated SMS Retriever Api and its working fine on devices with latest play services (checked with play services version 16.x.x and above)
The issue here is if I am running it on a device with Play Services 11.9.xx then the SMS Retriever client doesn't get registered also no error is thrown it simply skips over and doesn't work !!
But As per the docs -
Prerequisites -
The SMS Retriever API is available only on Android devices with Play
services version 10.2 and newer.
So it should have worked with my device as play services was greater than 10.2
Please suggest what I am doing wrong !!
The code used to register client :
fun setRetrieveSmsTaskListener(context: Context) {
val client = SmsRetriever.getClient(context)
val task = client.startSmsRetriever()
task.addOnSuccessListener {
LogUtils.debugLog(LOG_TAG, "Sms retriever api task Success")
}
task.addOnFailureListener {
LogUtils.debugLog(LOG_TAG, "Failure Sms retriever api task with exception $it")
}
task.addOnCanceledListener {
LogUtils.debugLog(LOG_TAG, "Canceled Sms retriever api task with exception")
}
}
And the depencies used :
implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'

Use lower version of play service(like below) and try again
implementation 'com.google.android.gms:play-services-auth-api-phone:11.0.4'
Or update the google play service version on device if you are using latest version of dependencies.

Related

com.google.android.gms.common.api.ApiException: 17: API: Games.API is not available on this device

recently I ported my old Android game developed in Eclipse from 2011-2016, to Android Studio because I was forced to a much higher MinSdk by Google. To the following according to build.gradle:
compileSdk 30
minSdk 26
targetSdk 31
Everything worked fine after the porting, but I am not able to get the GooglePlayServices (Leaderboards, Achievements) working again.
I am able to trigger that the user signs in with it GooglePlay account. This works and I get the account and can log its name. That is working.
mGoogleSignedInAccount = completedTask.getResult(ApiException.class);
Log.e(TAG, "account: " + mGoogleSignedInAccount.getDisplayName());
But when I try open the leaderboard, so that the user can see their highscore compared to other players
LeaderboardsClient lbc = Games.getLeaderboardsClient(v.getContext(),
ApplSettings.getInstance()._mainActivity).mGoogleSignedInAccount);
Task<Intent> lbt = lbc.getAllLeaderboardsIntent();
lbt.addOnSuccessListener(new OnSuccessListener<Intent>() {
public void onSuccess(Intent intent) {
Log.d(TAG," ..onSuccess");
((Activity) (v.getContext())).startActivityForResult( intent, 9004 );
}
});
lbt.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.d(TAG,".. onFailure: "+e.toString());
}
});
I get the following error:
.. onFailure: com.google.android.gms.common.api.ApiException:
17: API: Games.API is not available on this device.
Connection failed with: ConnectionResult{statusCode=DEVELOPER_ERROR, resolution=null, message=null}
I really don't understand this error. What does it mean? It is independent of the phones I use (OnePlus6T, Samsung Galaxy S9). And of course other game apps on those phones, including my other older games app, can show Leaderboards!
What is also strange, is the following message in the GooglePlayConsole of my app in Play-GamesSevice->Configuration.
It says the 5 tasks have to be done to enable the Play-GameServices, and its states that 4 have been done, and 1 task is remaing:
Play-GameService enabling:
Create a Play GamesService project -> done
Create OAuth ConfirmationScreen in the Google Cloud Platform -> done
Create Credentials -> done
Add the SDK for Google Play-GamesServices to your production APK -> OPEN !!!
Publish Project -> done
What does point 4 mean? How to add an SDK to my games app?
Is it not enough to mention those play-service 'libraries' in the build.gradle of my app?
buildscript {
repositories {
google()
mavenCentral()
}
}
dependencies {
. . .
implementation 'com.google.android.gms:play-services-games:23.1.0'
implementation 'com.google.android.gms:play-services-measurement-api:20.0.0'
implementation 'com.google.android.gms:play-services-auth:20.4.1'
}
So I am not sure if this task (number 4) mentioned by Google as outstanding, is related to the error "Games.API is not available on this device", but it would make sense.
But still I don't understand "not available on this device"? Does not the app is build with libraries that communicate with the Google services in the cloud? What shall be missing on the device? All games app (my other very old game, and also very new apps) can without problem show leaderboards on my devices I use for testing.

Dependency for SMS Retriever API

I am trying to implement SMS Retriever API, but I am unable to find classes like SmsRetrieverClient. I'm not able to import them.
Refer to the following sample code:
SmsRetrieverClient client = SmsRetriever.getClient(context);
Task<Void> task = client.startSmsRetriever();
task.addOnSuccessListener(new OnSuccessListener<Void>() {});
I have added following dependency, after which I am able to refer the classes:
compile 'com.google.android.gms:play-services:11.0.2'
But as this include all service API, I want to know the dependency specific to SMS Retriever API
I have referred to this doc for all dependency and added following, but it did not work.
com.google.android.gms:play-services-auth:11.0.2
com.google.android.gms:play-services-identity:11.0.2
Also, is it necessary to have 11.x.x versions?
Try adding the following dependency:
implementation "com.google.android.gms:play-services-auth-api-phone:$playServicesVersion"
replace $playServicesVersion with the play services version you are using.
Do you have error logs that may show the problem? For the meantime, try the old version first from the SMS Retriever document:
The SMS Retriever API is available only on Android devices with Play
services version 10.2 and newer.
Check this one if the old version imports SmsRetrieverClient successfully.

LVL fails (0x101 ERROR_CONTACTING_SERVER) w/ Android V2.3.5

I have a paid app on the Google Play Store and have been using the LVL library for the past two years. In the past, I tested my app on multiple devices including Android V2.3.5 (Gingerbread), V4.4 (KitKat) and V5.1 (Lollipop), everything worked fine connecting to the google license server.
Recently, I retested on all my Android devices and found the license verification library runs perfectly on Android V4.4 and V5.1 but I can't make a successful connection from the V2.3.5 (Gingerbread) device (Motorola Electrify).
I get a responseCode = 0x101 (ERROR_CONTACTING_SERVER) in the verify() callback on the older v2.3.5 device - appears to time out connecting. I tried several accounts and both fail in the same way on the older Gingerbread platforms.
I also tested earlier APK files that used to work and they fail now also.
Did support for older Android OS versions get dropped over the past year?
Is there something I need to change to support the older devices?
Thanks in advance,
Phil
SDK LVL code
class LicenseValidator {
...
public void verify(PublicKey publicKey, int responseCode, String signedData, String signature) {
String userId = null;
// Skip signature check for unsuccessful requests
ResponseData data = null;
if (responseCode == LICENSED || responseCode == NOT_LICENSED ||
responseCode == LICENSED_OLD_KEY) {
// Verify signature.
...
switch (responseCode) {
case LICENSED:
case LICENSED_OLD_KEY:
int limiterResponse = mDeviceLimiter.isDeviceAllowed(userId);
handleResponse(limiterResponse, data);
break;
case NOT_LICENSED:
handleResponse(Policy.NOT_LICENSED, data);
break;
case ERROR_CONTACTING_SERVER:
Log.w(TAG, "Error contacting licensing server.");
handleResponse(Policy.RETRY, data);
break;
case ERROR_SERVER_FAILURE:
Log.w(TAG, "An error has occurred on the licensing server.");
handleResponse(Policy.RETRY, data);
break;
Okay, I figured it out tonight. Post Google Play Services 10.0.1, support for Gingerbread V2.3 is depreciated.
https://9to5google.com/2016/11/21/google-play-services-gingerbread-support-end/
https://developers.google.com/android/guides/releases
"Highlights from the Google Play services 10.0 release.
Google Play services updated to 10.0.1
This release fixes a missing minSdkVersion value in play-services-location.aar that caused unintended WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE, and READ_PHONE_STATE permissions to be merged into app manifests.
Android version 2.3.x (Gingerbread) Deprecation
Google Play services 10.0.x is the final release that includes full support for Android version 2.3.x (Gingerbread). Apps developed using future SDK releases after 10.0.x will not be able to connect to Google Play services on Android Gingerbread devices. To learn more about your options, including building multiple APKs to extend your app's support for Android Gingerbread, see the Android Developers Blog."
Phil

Registering endpoints - Member must not be null (Service: AmazonSNS;

Testing on android 4.2.2, API 17 (simulated). This works with API 21+ (hard and simulated devices).
Caused by: com.amazonaws.AmazonServiceException: 1 validation error
detected: Value null at 'token' failed to satisfy constraint: Member
must not be null (Service: AmazonSNS; Status Code: 400; Error Code:
ValidationError; Request ID:
Using firebase token to register a device endpoint (to AWS SNS) with method below and getting error above. It fails on line
CreatePlatformEndpointResult cpeRes = client.createPlatformEndpoint(cpeReq);
Method:
private String createEndpoint() {
String endpointArn = null;
try {
System.out.println("Creating platform endpoint with token " + token);
CreatePlatformEndpointRequest cpeReq =
new CreatePlatformEndpointRequest()
.withPlatformApplicationArn(applicationArn)
.withToken(token);
CreatePlatformEndpointResult cpeRes = client.createPlatformEndpoint(cpeReq);
endpointArn = cpeRes.getEndpointArn();
} catch (Exception ipe) {
String message = ipe.toString();
System.out.println("Exception message: " + message);
Pattern p = Pattern
.compile(".*Endpoint (arn:aws:sns[^ ]+) already exists " +
"with the same token.*");
Matcher m = p.matcher(message);
if (m.matches()) {
// The platform endpoint already exists for this token, but with
endpointArn = m.group(1);
} else {
// Rethrow the exception, the input is actually bad.
throw ipe;
}
}
storeEndpointArn(endpointArn);
return endpointArn;
}
So after hours of playing with the code, the problem is not with the code, but with the emulator.
Google Play Services
To develop an app using the Google Play services APIs, you need to set
up your project with the Google Play services SDK.
If you haven't installed the Google Play services SDK yet, go get it
now by following the guide to Adding SDK Packages.
To test your app when using the Google Play services SDK, you must use
either:
A compatible Android device that runs Android 2.3 or higher and
includes Google Play Store. The Android emulator with an AVD that runs
the Google APIs platform based on Android 4.2.2 or higher.
So on API 17...
API 17 (Android 4.2-4.2.2) – Jelly Bean, released November 2012. Build
version code Android.OS.BuildVersionCodes.JellyBeanMr1
So, to emulate this on API 17 and up, open the SDK installer, and show package details. In the API version to be emulated, install all packages relating to Google APIs. This gives you an idea.

Google play services out of date. Requires 5089000 but found 3136130

I'm trying to use Google cloud messaging for an android app (Target name: Google APIs, platform: 4.3, API level: 18. I implemented my GCM client by following the isntructions here: http://developer.android.com/google/gcm/client.html, and setup play services by following the steps here:
http://developer.android.com/google/play-services/setup.html#Setup, but still get the above error Most of the solutions I've found on stack overflow redirect to the above two links, or suggest that we change the dependencies {} in the gradle settings, but I'm using eclipse and don't have gradle setup.
Update: Sorry yes I'm using the emulator and not a device
Any ideas?Thanks!
If you need to provide an option for the user to update the google services you can do this:
switch (isGooglePlayServicesAvailable(this)) {
case 2: //out date
try {
GooglePlayServicesUtil.getErrorDialog(2, this, 0).show();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
This will prompt an update dialog for the user to update play services
The final solution was creating a new emulator under Android 4.4.2, with the build target of the project set to Google APIs (x86 System Image). Thanks to Pedro Oliveira!

Categories

Resources