Skip to content

Commit f8c19c9

Browse files
committed
Check GooglePlayServicesUtil and fixed gms prompt
* Now prompts for Google Play services missing again. * Added check for GooglePlayServicesUtil to better detect missing gms components.
1 parent a11751e commit f8c19c9

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

OneSignalSDK.jar

121 Bytes
Binary file not shown.

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void init() {
160160
private static TrackGooglePurchase trackGooglePurchase;
161161
private static TrackAmazonPurchase trackAmazonPurchase;
162162

163-
public static final String VERSION = "020501";
163+
public static final String VERSION = "020502";
164164

165165
private static AdvertisingIdentifierProvider mainAdIdProvider = new AdvertisingIdProviderGPS();
166166

@@ -243,6 +243,13 @@ public static void init(Context context, String googleProjectNumber, String oneS
243243
Log(LOG_LEVEL.FATAL, "The GCM Google Play services client library was not found. Please make sure to include it in your project.", e);
244244
subscribableStatus = -4;
245245
}
246+
247+
try {
248+
Class.forName("com.google.android.gms.common.GooglePlayServicesUtil");
249+
} catch (ClassNotFoundException e) {
250+
Log(LOG_LEVEL.FATAL, "The GooglePlayServicesUtil class part of Google Play services client library was not found. Include this in your project.", e);
251+
subscribableStatus = -4;
252+
}
246253
}
247254

248255
mGoogleProjectNumber = googleProjectNumber;

OneSignalSDK/onesignal/src/main/java/com/onesignal/PushRegistratorGPS.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ private boolean isGooglePlayStoreInstalled() {
8080
}
8181

8282
private boolean checkPlayServices() {
83+
// GoogleApiAvailability is the replacement for GooglePlayServicesUtil added in 7.3.
84+
8385
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(appContext);
8486
if (resultCode != ConnectionResult.SUCCESS) {
8587
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode) && isGooglePlayStoreInstalled()) {
@@ -103,15 +105,18 @@ private boolean checkPlayServices() {
103105
}
104106

105107
private void ShowUpdateGPSDialog(final int resultCode) {
106-
((Activity) appContext).runOnUiThread(new Runnable() {
108+
OneSignal.runOnUiThread(new Runnable() {
107109
@Override
108110
public void run() {
109-
AlertDialog.Builder builder = new AlertDialog.Builder(appContext);
111+
final Activity activity = ActivityLifecycleHandler.curActivity;
112+
if (activity == null)
113+
return;
114+
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
110115
builder.setMessage("To receive push notifications please press 'Update' to enable 'Google Play services'.").setPositiveButton("Update", new OnClickListener() {
111116
@Override
112117
public void onClick(DialogInterface dialog, int which) {
113118
try {
114-
GooglePlayServicesUtil.getErrorPendingIntent(resultCode, appContext, 0).send();
119+
GooglePlayServicesUtil.getErrorPendingIntent(resultCode, activity, 0).send();
115120
} catch (CanceledException e) {
116121
} catch (Throwable e) {
117122
e.printStackTrace();
@@ -121,7 +126,7 @@ public void onClick(DialogInterface dialog, int which) {
121126
}).setNegativeButton("Skip", new OnClickListener() {
122127
@Override
123128
public void onClick(DialogInterface dialog, int which) {
124-
final SharedPreferences prefs = OneSignal.getGcmPreferences(appContext);
129+
final SharedPreferences prefs = OneSignal.getGcmPreferences(activity);
125130
SharedPreferences.Editor editor = prefs.edit();
126131
editor.putBoolean("GT_DO_NOT_SHOW_MISSING_GPS", true);
127132
editor.commit();

0 commit comments

Comments
 (0)