I have an app that uses Google Maps. Since, with the new Api in Android, the map wont work if the user don't have the Google Maps app up to date, is there any way that my app can know the version that the user have installed? And... can my app know wich version is the last in Google Play?
the map wont work if the user don't have the Google Maps app up to date, is there any way that my app can know the version that the user have installed?
Your app does not care about the version of Google Maps. Your app cares about having the Play Services Framework installed.
My sample apps, such as this one, use an AbstractMapActivity that wraps up the details of checking for the Play Services Framework, in a call to readyToGo():
protected boolean readyToGo() {
int status=
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status == ConnectionResult.SUCCESS) {
return(true);
}
else if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
ErrorDialogFragment.newInstance(status)
.show(getSupportFragmentManager(),
TAG_ERROR_DIALOG_FRAGMENT);
}
else {
Toast.makeText(this, R.string.no_maps, Toast.LENGTH_LONG).show();
finish();
}
return(false);
}
This will return true if isGooglePlayServicesAvailable() itself returns true. Otherwise, if possible, it will display a dialog (there's an ErrorDialogFragment inner class) that will lead the user to install the Play Services Framework. Or, it will display a Toast for an unrecoverable problem (though production code should use something else, like a crouton).
GooglePlayServicesUtil has its own set of JavaDocs.
Related
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)?
According to the documentation GooglePlayServicesUtil.isGooglePlayServicesAvailable returns SERVICE_VERSION_UPDATE_REQUIRED when "The installed version of Google Play services is out of date".
Does this mean that there is a new version of google play services in the play store?
Does this mean that the app needs a newer version than the one that is currently installed in the device?
How is this check done?
this means that the version of google play service you included in your app is higher than the one currently installed on the users device. the user needs to update their google play services in-order for your app to work correctly.
if the result comes back with that error you can simply call this method to alert the user they need to update and it will take them there.
GooglePlayServicesUtil.getErrorDialog(result, this, GOOGLE_PLAY_SERVICE_UPDATE_CODE).show();
result is the result of the isGooglePlayServicesAvailable method
Here are the docs for GooglePlayServicesUtil: http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html.
Here is where they talking about "ensuring" the user has it installed: https://developer.android.com/google/play-services/setup.html#ensure
This is taken from the Official Iosched 2014 source code here:
https://github.com/google/iosched/blob/0a90bf8e6b90e9226f8c15b34eb7b1e4bf6d632e/android/src/main/java/com/google/samples/apps/iosched/util/PlayServicesUtils.java
public class PlayServicesUtils {
public static boolean checkGooglePlaySevices(final Activity activity) {
final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
switch (googlePlayServicesCheck) {
case ConnectionResult.SUCCESS:
return true;
case ConnectionResult.SERVICE_DISABLED:
case ConnectionResult.SERVICE_INVALID:
case ConnectionResult.SERVICE_MISSING:
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
#Override
public void onCancel(DialogInterface dialogInterface) {
activity.finish();
}
});
dialog.show();
}
return false;
}
}
Here is how to use it in an Activity: https://github.com/google/iosched/blob/cf1f30b4c752f275518384a9b71404ee501fc473/android/src/main/java/com/google/samples/apps/iosched/ui/BaseActivity.java
#Override
protected void onResume() {
super.onResume();
// Verifies the proper version of Google Play Services exists on the device.
PlayServicesUtils.checkGooglePlaySevices(this);
}
Does this mean that there is a new version of google play services in the play store?
From the site latest update was on December 2014
Does this mean that the app needs a newer version than the one that is currently installed in the device?
You can check if the device has the higher version ofGoogle Play Service than the one on your app like so:
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable( getApplicationContext() );
if(status == ConnectionResult.SUCCESS) {
//OK
}else if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
Toast.makeText(context,"please udpate your google play service",Toast.LENGTH_SHORT).show
}
Documentation was updated, now it is clear:
Verifies that Google Play services is installed and enabled on this
device, and that the version installed on this device is no older than
the one required by this client.
Note that all of the current answers reference GooglePlayServicesUtil which is now deprecated. See GooglePlayServicesUtil vs GoogleApiAvailability for details on how to perform the Google Play Services version compatibility check.
I resolved this problem by updating the last version of Youtube library available in : https://developers.google.com/youtube/android/player/downloads
In the gradle :
implementation files('libs/YouTubeAndroidPlayerApi.jar')
My Android app requires Google Play services to display Google Maps. I've included a function call that checks for the availability of Google Play services and proceed if it exists. If it doesn't exist or has an outdated version, an error dialog is shown that redirects user to Play Store. I wanted to ask, how can I check if a user has actually installed (or updated) Google Play services when they land back to my app? I'm using Fragment and checking for the availability of Google Play services in onResume().
The function is as follow:
private boolean isPlayServicesConfigured() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getApplicationContext());
if(status == ConnectionResult.SUCCESS)
return true;
else {
Log.d("STATUS", "Error connecting with Google Play services. Code: " + String.valueOf(status));
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), status);
dialog.show();
return false;
}
}
Moreover, even if I get the status of Google Play Services back in my app, how do I reload the fragment? Can I call onCreateView() programatically?
I am trying to implement the google play services sign-in to my app.
I added libraries (Google-play-services lib, basegameutils lib).I have added the sign in button. The app is not crashing. Everything that I have done seems to be ok.
I signed the app with the keytool and export it, then install it to my phone. I added the SHA1 code to my test app on developers console. And added My app Id to my app.
But when I tap on the sign in button it say with a pop-up "this app won\'t work unless you update google play services". When tap on the "update" it seems the service is up to date.
Is this a problem with my device? Or else What can I try to solve that?
My device is Samsung Galaxy S3.
Update
I added this code :
private boolean checkIfMapsIsOk() {
int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, this, 1122).show();
Toast.makeText(getApplicationContext(), "err"+checkGooglePlayServices, Toast.LENGTH_SHORT).show();
return false;
} else {
Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show();
return true;
}
}
and the toast result is "err2". And I looked up for the error numbers from http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html
It says on that site "public static final int SERVICE_VERSION_UPDATE_REQUIRED"
"The installed version of Google Play services is out of date. The calling activity should pass this error code to getErrorDialog(int, Activity, int) to get a localized error dialog that will resolve the error when shown.
Constant Value: 2 (0x00000002)"
So from this I think the reason for error is my device. But my device sees no updates. It is up to date. This is so strange.
I have an app that uses Google Maps Android API v2 and therefore uses Google Play Services.
The problem I have is: How can I help those users that doesn't have Google Play Services installed?
I'm doing the usual check for the services:
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
switch (result) {
case ConnectionResult.SUCCESS:
startActivity(new Intent(this, Map.class));
break;
and if the result is no good I show a dialog with an option to the user:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Error mesage").setTitle("Error message title");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
GooglePlayServicesUtil.getErrorDialog(result, MainMenu.this, 32).show();
dialog.dismiss();
}
});
When the user clickes "Yes" and are prompted with the Google Play Services the user clickes on that and are in the most cases forwarded to the Google Play store. But here there is another error message from Google Play saying something like "Unit (Phone) is not compatible with this version", which I think is odd because I'm using a HTC Sensation Z710e which I recently updated to 4.0.3 of android.
On my other phone HTC Wildfire S A510e with Android 2.3.5 nothing happens when the user clicks on the "Get Google Play Services" button from the GooglePlayServicesUtil.getErrorDialog.
Any ideas what I can do to help the user get Google Play services?
Thanks
You can try 2 things:
1.Debug and find out the value of result from isGooglePlayServicesAvailable method. In case of failure it should be one of these values:
SERVICE_MISSING,
SERVICE_VERSION_UPDATE_REQUIRED,
SERVICE_DISABLED,
SERVICE_INVALID
So you know why exactly the Google Play services APK is not available.
2.Note that Phone not compatible with this version - this message is sometimes shown to user when appropriate feature is not mentioned in uses-feature tag of android manifest.
Choose a correct feature from the Feature Reference list for in your manifest and take appropriate note of uses-sdk and permission tags.