Google Play Services Vision check availability - android

I've tried to use GooglePlayServices Vision package in my app. I've tried in 4 devices and 3 give me that "dependencies are not yet available" on
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
if(!barcodeDetector.isOperational()){
//show dependencies are not yet available
}
The problem is that even if I close and reopen my app, when I go in the ScanQRCodeActivity i obtain always this error.
So I've seen for the PlayServices availability though
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
if(googleAPI.isGooglePlayServicesAvailable(this) != ConnectionResult.SUCCESS) {
//show dialog
}
but it returns always SUCCESS.
My manifest have meta-data
<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode" />
And my gradle have the
implementation 'com.google.android.gms:play-services-vision:15.0.2'
Anyway, the only thing that works for me is Clear data of Google Play Services, but people that use my app don't know this.
Have you any idea?
Thanks.

From this SO post, same problem was encountered. You may pick some important points there. Also when you visit the Google Play Services 9.2 bug fixes, there are some tips that you can follow to resolve some issues.

Related

How to fix apiAvailability.isGooglePlayServicesAvailable misbehaving on emulator

I'm developing an application that uses google maps and I encountered a weird problem when trying to launch my app on emulator - it (obviously) doesn't work and shows an error message "MyApp having trouble with Google Play services. Please try again".
To solve this problem, I decided to check the availability of Google Play Services (as recommended in this guide by Google https://developers.google.com/android/guides/setup). And.. it doesn't work as intended.
So, here's the code I use to check the availability of Google Play Services and the result code for the emulator is always SUCCESS, even though it doesn't have the desired version installed.
private fun checkPlayServices(): Boolean {
val apiAvailability = GoogleApiAvailability.getInstance()
val resultCode = apiAvailability.isGooglePlayServicesAvailable(activity)
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this.activity, resultCode, 9000)
.show()
} else {
Timber.tag("tag").e("This device is not supported.")
}
return false
}
return true
}
In logs I can clearly see the message
W/GooglePlayServicesUtil: Google Play services out of date. Requires 13400000 but found 13280022
And I cannot comprehend why Google says that there are google play services installed on a version without google play service
I expected this function to return some kind of error and show the correct dialog, but it just returns success for the emulator.
Though, if I run it on a version WITHOUT google API, it shows the error correctly about not having google play services completely.
So, my question is - is it a problem with emulator or API and will it misbehave like this on normal phones or this is just an emulator bug (feature)?

No need to manually check Google Play Services version anymore?

It's been a while since I worked with Google Play Services and I'm now implementing a feature that requires location tracking. After following a dated example that used GoogleApiClient, I found this post about the new Location APIs at Android Developers blog:
https://android-developers.googleblog.com/2017/06/reduce-friction-with-new-location-apis.html
FusedLocationProviderClient client =
LocationServices.getFusedLocationProviderClient(this);
client.requestLocationUpdates(LocationRequest.create(), pendingIntent)
.addOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(#NonNull Task task) {
Log.d("MainActivity", "Result: " + task.getResult());
}
});
}
What caught my attention was something written at the bottom of the post, saying:
The new API will automatically resolve certain connection failures for
you, so you don't need to write code that for things like prompting
the user to update Google Play services.
Since I've already written that piece of code using GoogleApiAvailabilty I'm curious if it's safe to just remove it and let the FusedLocationProviderClient take care of it?
I've tried to find another source to verify this but failed, not really satisfied with half a line at the bottom of a blog post, hence posting the question here.
Ok so I'll answer my own question after a quick test. I temporarily removed the checks that made sure Google Play Services was available and the correct version. Then installed the app on an emulator without Google Play Services and when I try to use the LocationServices API I get a sticky headsup notification saying:
[app name] won't run unless you update Google Play Services.
So I guess it's safe to remove the checks.
Worth noting is that it seems the listeners (Success/Failure/Complete) are not called unless the user actually interacts with the notification, if they for example just press something else in your apps UI, the listeners were not called.

ACL_ACCESS_DENIED Awareness API - Android

I am trying to integrate Awareness API on a new project and I am stuck with an error saying: ACL_ACCESS_DENIED Status Code: 7503.
I have integrated Awareness API on other projects as well, but the last time I encountered that error, it was due to the lack of declaration on a needed permission, for the DetectedActivity feature to work.
This time though, I am just using the Location feature of the Awareness API.
I have also tried to change API keys, regenerate them and even enable/disable the API itself, from Google API Console, but without any luck.
I also have a proper Google Services JSON file and the version of Play Services I am using is: 10.0.0
compile 'com.google.android.gms:play-services-awareness:10.0.0'
Below is the code I am using:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<meta-data
android:name="com.google.android.awareness.API_KEY"
android:value="MY_API_KEY"/>
this.googleApiClient = GoogleApiClient.Builder(this)
.addApi(Awareness.API)
.addConnectionCallbacks(this)
.enableAutoManage(this, this)
.build()
Awareness
.SnapshotApi
.getLocation(googleApiClient)
.setResultCallback {
handleLocationResult(it)
}
I have done a lot of Google searching as well, but no hints other than a SO post talking about the same error on Emulators. I am not trying it on an Emulator. I am using a real device to test it.
If anyone has any ideas, I would be grateful!
Thanks in advance!
Apparently, AwarenessAPI does return such an error for different cases.
The Status Code: 7503 will be returned even if you:
Missing a Permission from your Manifest, such as the one for DetectedActivity
Have the Location setting off when requesting a Location snapshot (it does not cause the Location Settings dialog to pop-up)
I will leave it here, in case someone else stumbles upon such a case, in the future!

getOpenSourceSoftwareLicenseInfo is returning null now

A trivial but annoying issue has come up in the last few days.
Previously my menu option which popped up a dialog to show the legal text for using Google Services was very full (if a little slow to load), but now it is null with no change to the code..
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode == ConnectionResult.SUCCESS) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("About");
builder.setMessage(apiAvailability.getOpenSourceSoftwareLicenseInfo(this));
builder.setPositiveButton("OK", null);
builder.show();
}
Is this a problem common to others, i.e. a new bug introduced by a Google update or some other possibility?
according to https://code.google.com/p/gmaps-api-issues/issues/detail?id=9813
It appears that google changed the file name it was looking for from oss_notice to third_party_licenses. They basically broke getting the license info for any play services implementation below 9.0.0.
you will need to update the version to 9.0.0 to get the license info back for device with later versions of play services.
EDIT (June 6, 2016): Google is looking into the issue now.
Project Member #3 l...#google.com
Thanks for the reports. We've filed
this internally and will look into it.
Status: Accepted Labels:
Internal-29143355
Yes, upgrading Google Play Services to last version (9.0.0 at time of writing this answer) solves the issue.
I had the same problem and after upgrading Google Play Services I started getting the licenses properly.
If you're maintaining an old app and can't reasonably update from a very old version of Google Play Services without breaking a whole lot of ancient features, there's a viable workaround:
Decompile the getOpenSourceSoftwareLicenseInfo() method with Android Studio, copy the method into your project, and change the line to point from "oss_notice" to "third_party_licenses".
Uri var1 = (new android.net.Uri.Builder()).scheme("android.resource").authority("com.google.android.gms").appendPath("raw").appendPath("oss_notice").build();
to
Uri var1 = (new android.net.Uri.Builder()).scheme("android.resource").authority("com.google.android.gms").appendPath("raw").appendPath("third_party_licenses").build();
This method has been deprecated and is no longer necessary:
https://developers.google.com/android/reference/com/google/android/gms/common/GooglePlayServicesUtil.html#getOpenSourceSoftwareLicenseInfo(android.content.Context)
This license information is displayed in Settings > Google > Open Source on any device running Google Play services. Applications do not need to display this license text, and this method will be removed in a future version of Google Play services.
👍

How do I determine the actual build number for Google Play Services on Android?

NOTE: I am not trying to update google play services in the emulator. I do not care that it is out of date. I mentioned it only to show that somehow logcat is reporting the actual build number, which I wish to access in the app.
Similar, but not the same as, How can I determine the version of Google Play services?
An app I'm developing using Android Studio 1.2.2 is experiencing a problem if the latest Google Play Services is not installed on the device, yet GoogleApiAvailability is not reporting a problem and so the code instructing the user to update is never called. If I manually tell the users to update play services in the play store with a manual link to https://play.google.com/store/apps/details?id=com.google.android.gms&hl=en, there is an update available, and the app functions correctly after they install it.
However I am unable to find a way to determine that the user needs to update via application code or the gradle build file.
In the gradle file I've specified: compile 'com.google.android.gms:play-services:7.5.0' and this is the latest version as far as I know. Android Studio does not indicate that I should update this line to a newer version.
The SDK manager reports the play services I have installed is "rev 25", and no update is available.
When I test in an emulator, the code works correctly, and in logcat I see the message: "W/GooglePlayServicesUtil: Google Play services out of date. Requires 7571000 but found 6774470". This is normal for the emulator since they haven't released new images yet, but it provides an interesting clue.
Is there a way to get this build number reported in item 3 above, programatically? If so, I could compare against that rather than using the isgooglePlayServicesAvailable method of GoogleApiAvailability -- which I'm already using, but is reporting success on devices that need an update.
I've managed to do a little digging and answer my own question. The following code will do what I (and perhaps others) want.
PackageInfo pi = getPackageManager().getPackageInfo("com.google.android.gms", 0);
if (pi.versionCode < VERSION_YOU_WANT)
{
// instruct user to update
}
What I've done is wrap this in the required exception handler and run it if the API check reports SUCCESS. If the version is too low I call the getErrorDialog just like when the API check fails, with ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED instead of the returned SUCCESS value.
Doing this may require you to update your minimum SDK target. For example both my phone(5.0.1) and tablet(4.2.2) report success from the API check, and going to the play store does not show an update for either one; However, the installed build on the table is 7895032 while on the phone it's 7895438.
This function will tell the user to update the GooglePlaServices if an update is available. You can start the registration process, if this function returns true
private boolean checkPlayServices()
{
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS)
{
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode))
GooglePlayServicesUtil.getErrorDialog(resultCode, this, 9000).show();
else
{
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}

Categories

Resources