Why does the play-services-analytics dependency not include GooglePlayServicesUtil or GoogleApiAvailability classes?
You can see a list Google Play services dependencies here: https://developers.google.com/android/guides/setup
If you run gradlew dependencies
on your project, you will see the following:
+--- com.google.android.gms:play-services-analytics:8.4.0
| \--- com.google.android.gms:play-services-basement:8.4.0
| \--- com.android.support:support-v4:23.0.0 -> 23.1.1 (*)
\--- com.google.android.gms:play-services-base:8.4.0
\--- com.google.android.gms:play-services-basement:8.4.0 (*)
The dependnecy, compile 'com.google.android.gms:play-services-analytics:8.4.0'
depends on compile 'com.google.android.gms:play-services-basement:8.4.0'
.
For ConnectionResult
and GoogleApiAvailability
, you also need: compile 'com.google.android.gms:play-services-base:8.4.0'
.
Also, new HitBuilders.AppViewBuilder().build()
is deprecated in favor of new HitBuilders.ScreenViewBuilder().build()
.
GooglePlayServicesUtil.getErrorDialog is null
Google suggests (also in docs) calling getErrorDialog()
if the result code is SERVICE_MISSING
, SERVICE_VERSION_UPDATE_REQUIRED
or SERVICE_DISABLED
. So it may be that the last possible status code (SERVICE_INVALID
) is what's causing trouble.
I'm using the following code and so far it seems to work ok (testing in emulator, platform 2.3.3):
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity.getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS) {
activity.selectMap();
} else if (resultCode == ConnectionResult.SERVICE_MISSING ||
resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ||
resultCode == ConnectionResult.SERVICE_DISABLED) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 1);
dialog.show();
}
getErrorDialog is depreciated. What is the updated function, and how might I use it?
However, when I put the getErrorDialog in, it stated that the method
was depreciated, and that I needed to use an 'updated' version.
GooglePlayServicesUtil.getErrorDialog
has been deprecated in favour of GoogleApiAvailability.getErrorDialog
, which is not a static method as it was for GooglePlayServicesUtil
. You can get an instance of GoogleApiAvailability
this way
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
and call getErrorDialog
on the returned instance
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST).show();
where this is a Context
's object and resultCode
is the return value of isGooglePlayServicesAvailable(Context)
. You can read more about it here
Google Cloud Messaging: how to ask for google play services availability with GoogleApiAvailability Class
Try this,
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.e(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
Check if correct Google Play Service available: Unfortunately application has stopped working
Thanks guys for your responses. I just figured it out from my LogCat.
I had to include this in my Android Manifest.
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
...
When does isGooglePlayServicesAvailable return SERVICE_VERSION_UPDATE_REQUIRED?
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.
What does my min-sdk version need to be in order to use GoogleApiAvailability?
https://developers.google.com/android/guides/setup
states: "The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher."
So that's 17 or higher
Related Topics
Image Size (Drawable-Hdpi/Ldpi/Mdpi/Xhdpi)
First Letter Capitalization for Edittext
How to Change Line Color in Edittext
Unable to Execute Adb in Ubuntu. Downloaded File Is Meant for X86-64 While I Have I686
Javafxports How to Call Android Native Media Player
Understanding Android: Zygote and Dalvikvm
Android How to Implement Bottom Sheet from Material Design Docs
How to Make APK Secure. Protecting from Decompile
Android: Volley Http Request Custom Header
Get Launchable Activity Name of Package from Adb
Handling Back Button in Android Navigation Component
Run Lint When Building Android Studio Projects