2727
2828package com .onesignal ;
2929
30- import com .google .android .gms .common .ConnectionResult ;
3130import com .google .android .gms .common .GooglePlayServicesUtil ;
3231import com .google .android .gms .gcm .GoogleCloudMessaging ;
3332
@@ -58,10 +57,10 @@ public void registerForPush(Context context, String googleProjectNumber, Registe
5857 registeredHandler = callback ;
5958
6059 try {
61- if (checkPlayServices ())
60+ if (isGMSInstalledAndEnabled ())
6261 registerInBackground (googleProjectNumber );
6362 else {
64- OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "No valid Google Play services APK found ." );
63+ OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "' Google Play services' app not installed or disabled on the device ." );
6564 registeredHandler .complete (null , -7 );
6665 }
6766 } catch (Throwable t ) {
@@ -81,34 +80,28 @@ private boolean isGooglePlayStoreInstalled() {
8180 return false ;
8281 }
8382
84- private boolean checkPlayServices () {
85- // GoogleApiAvailability is the replacement for GooglePlayServicesUtil added in 7.3.
86-
87- int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable (appContext );
88- if (resultCode != ConnectionResult .SUCCESS ) {
89- if (GooglePlayServicesUtil .isUserRecoverableError (resultCode ) && isGooglePlayStoreInstalled ()) {
90- OneSignal .Log (OneSignal .LOG_LEVEL .INFO , "Google Play services Recoverable Error: " + resultCode );
83+ private boolean isGMSInstalledAndEnabled () {
84+ try {
85+ PackageManager pm = appContext .getPackageManager ();
86+ PackageInfo info = pm .getPackageInfo ("com.google.android.gms" , PackageManager .GET_ACTIVITIES );
9187
88+ if (!info .applicationInfo .enabled && isGooglePlayStoreInstalled ()) {
9289 final SharedPreferences prefs = OneSignal .getGcmPreferences (appContext );
9390 if (prefs .getBoolean ("GT_DO_NOT_SHOW_MISSING_GPS" , false ))
9491 return false ;
9592
9693 try {
97- ShowUpdateGPSDialog (resultCode );
94+ ShowUpdateGPSDialog ();
9895 } catch (Throwable t ) {}
9996 }
100- else
101- OneSignal .Log (OneSignal .LOG_LEVEL .WARN , "Google Play services error: This device is not supported. Code:" + resultCode );
102-
103- return false ;
104- }
105-
106- return true ;
107- }
10897
98+ return info .applicationInfo .enabled ;
99+ } catch (PackageManager .NameNotFoundException e ) {}
109100
101+ return false ;
102+ }
110103
111- private void ShowUpdateGPSDialog (final int resultCode ) {
104+ private void ShowUpdateGPSDialog () {
112105 OneSignal .runOnUiThread (new Runnable () {
113106 @ Override
114107 public void run () {
@@ -126,6 +119,7 @@ public void run() {
126119 @ Override
127120 public void onClick (DialogInterface dialog , int which ) {
128121 try {
122+ int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable (appContext );
129123 GooglePlayServicesUtil .getErrorPendingIntent (resultCode , activity , 0 ).send ();
130124 } catch (CanceledException e ) {
131125 } catch (Throwable e ) {
0 commit comments