27
27
28
28
package com .onesignal ;
29
29
30
- import com .google .android .gms .common .ConnectionResult ;
31
30
import com .google .android .gms .common .GooglePlayServicesUtil ;
32
31
import com .google .android .gms .gcm .GoogleCloudMessaging ;
33
32
@@ -58,10 +57,10 @@ public void registerForPush(Context context, String googleProjectNumber, Registe
58
57
registeredHandler = callback ;
59
58
60
59
try {
61
- if (checkPlayServices ())
60
+ if (isGMSInstalledAndEnabled ())
62
61
registerInBackground (googleProjectNumber );
63
62
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 ." );
65
64
registeredHandler .complete (null , -7 );
66
65
}
67
66
} catch (Throwable t ) {
@@ -81,34 +80,28 @@ private boolean isGooglePlayStoreInstalled() {
81
80
return false ;
82
81
}
83
82
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 );
91
87
88
+ if (!info .applicationInfo .enabled && isGooglePlayStoreInstalled ()) {
92
89
final SharedPreferences prefs = OneSignal .getGcmPreferences (appContext );
93
90
if (prefs .getBoolean ("GT_DO_NOT_SHOW_MISSING_GPS" , false ))
94
91
return false ;
95
92
96
93
try {
97
- ShowUpdateGPSDialog (resultCode );
94
+ ShowUpdateGPSDialog ();
98
95
} catch (Throwable t ) {}
99
96
}
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
- }
108
97
98
+ return info .applicationInfo .enabled ;
99
+ } catch (PackageManager .NameNotFoundException e ) {}
109
100
101
+ return false ;
102
+ }
110
103
111
- private void ShowUpdateGPSDialog (final int resultCode ) {
104
+ private void ShowUpdateGPSDialog () {
112
105
OneSignal .runOnUiThread (new Runnable () {
113
106
@ Override
114
107
public void run () {
@@ -126,6 +119,7 @@ public void run() {
126
119
@ Override
127
120
public void onClick (DialogInterface dialog , int which ) {
128
121
try {
122
+ int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable (appContext );
129
123
GooglePlayServicesUtil .getErrorPendingIntent (resultCode , activity , 0 ).send ();
130
124
} catch (CanceledException e ) {
131
125
} catch (Throwable e ) {
0 commit comments