Skip to content

Commit 4fcc464

Browse files
committed
Bug fixes
* Fixed bug where notifications would not be displayed if the app was still running in the background unless enableNotificationsWhenActive was set to true. * Omitting Google Play specific error logging when running on Amazon devices.
1 parent c84511a commit 4fcc464

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

OneSignalSDK.jar

685 Bytes
Binary file not shown.

OneSignalSDK/app/src/main/java/com/onesignal/example/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ protected void onCreate(Bundle savedInstanceState) {
3535
// Pass in your app's Context, Google Project number, OneSignal App ID, and a NotificationOpenedHandler
3636
OneSignal.init(this, "703322744261", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", new ExampleNotificationOpenedHandler());
3737
//OneSignal.init(this, "703322744261", "5eb5a37e-b458-11e3-ac11-000c2940e62c", new ExampleNotificationOpenedHandler());
38-
OneSignal.enableInAppAlertNotification(false);
39-
OneSignal.enableNotificationsWhenActive(true);
38+
//OneSignal.enableInAppAlertNotification(false);
39+
//OneSignal.enableNotificationsWhenActive(true);
4040
//OneSignal.setSubscription(false);
4141

4242
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {

OneSignalSDK/app/src/main/java/com/onesignal/example/MainActivity2Activity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ protected void onCreate(Bundle savedInstanceState) {
2626
currentActivity = this;
2727

2828
OneSignal.init(this, "703322744261", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", new ExampleNotificationOpenedHandler());
29-
OneSignal.enableNotificationsWhenActive(true);
29+
//OneSignal.enableNotificationsWhenActive(true);
30+
}
31+
32+
@Override
33+
protected void onPause() {
34+
super.onPause();
35+
OneSignal.onPaused();
36+
}
37+
@Override
38+
protected void onResume() {
39+
super.onResume();
40+
OneSignal.onResumed();
3041
}
3142

3243
@Override

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,26 @@ public static void Process(Context context, Bundle bundle, Class<?> notification
4646
boolean isActive = OneSignal.initDone && OneSignal.isForeground();
4747
boolean display = OneSignal.getNotificationsWhenActiveEnabled(context)
4848
|| showAsAlert
49-
|| isActive;
49+
|| !isActive;
50+
5051
prepareBundle(bundle);
5152

5253
BackgroundBroadcaster.Invoke(context, bundle, isActive);
5354

5455
if (!bundle.containsKey("alert") || bundle.getString("alert") == null || bundle.getString("alert").equals(""))
5556
return;
5657

57-
if (!display) {
58+
if (display)// Build notification from the Bundle
59+
GenerateNotification.fromBundle(context, bundle, notificationOpenedActivityClass, showAsAlert && isActive);
60+
else {
5861
final Bundle finalBundle = bundle;
5962
// Current thread is meant to be short lived. Make a new thread to do our OneSignal work on.
6063
new Thread(new Runnable() {
6164
public void run() {
6265
OneSignal.handleNotificationOpened(finalBundle);
6366
}
6467
}).start();
65-
} else // Build notification from the Bundle
66-
GenerateNotification.fromBundle(context, bundle, notificationOpenedActivityClass, showAsAlert && isActive);
68+
}
6769
}
6870
}
6971

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public interface PostNotificationResponseHandler {
139139
private static TrackGooglePurchase trackGooglePurchase;
140140
private static TrackAmazonPurchase trackAmazonPurchase;
141141

142-
public static final String VERSION = "010901";
142+
public static final String VERSION = "010902";
143143

144144
private static PushRegistrator pushRegistrator;
145145
private static AdvertisingIdentifierProvider mainAdIdProvider = new AdvertisingIdProviderGPS();
@@ -155,6 +155,16 @@ public static void init(Activity context, String googleProjectNumber, String one
155155
}
156156

157157
public static void init(Activity context, String googleProjectNumber, String oneSignalAppId, NotificationOpenedHandler inNotificationOpenedHandler) {
158+
159+
try {
160+
Class.forName("com.amazon.device.messaging.ADM");
161+
pushRegistrator = new PushRegistratorADM();
162+
deviceType = 2;
163+
} catch (ClassNotFoundException e) {
164+
pushRegistrator = new PushRegistratorGPS();
165+
deviceType = 1;
166+
}
167+
158168
// START: Init validation
159169
try {
160170
UUID.fromString(oneSignalAppId);
@@ -166,14 +176,22 @@ public static void init(Activity context, String googleProjectNumber, String one
166176
if ("b2f7f966-d8cc-11eg-bed1-df8f05be55ba".equals(oneSignalAppId) || "5eb5a37e-b458-11e3-ac11-000c2940e62c".equals(oneSignalAppId))
167177
Log(LOG_LEVEL.WARN, "OneSignal Example AppID detected, please update to your app's id found on OneSignal.com");
168178

169-
try {
170-
Double.parseDouble(googleProjectNumber);
171-
if (googleProjectNumber.length() < 8 || googleProjectNumber.length() > 16)
172-
throw new IllegalArgumentException("Google Project number (Sender_ID) should be a 10 to 14 digit number in length.");
173-
}
174-
catch (Throwable t) {
175-
Log(LOG_LEVEL.FATAL, "Google Project number (Sender_ID) format is invalid. Please use the 10 to 14 digit number found in the Google Developer Console for your project.\nExample: '703322744261'\n", t, context);
176-
currentSubscription = -6;
179+
if (deviceType == 1) {
180+
try {
181+
Double.parseDouble(googleProjectNumber);
182+
if (googleProjectNumber.length() < 8 || googleProjectNumber.length() > 16)
183+
throw new IllegalArgumentException("Google Project number (Sender_ID) should be a 10 to 14 digit number in length.");
184+
} catch (Throwable t) {
185+
Log(LOG_LEVEL.FATAL, "Google Project number (Sender_ID) format is invalid. Please use the 10 to 14 digit number found in the Google Developer Console for your project.\nExample: '703322744261'\n", t, context);
186+
currentSubscription = -6;
187+
}
188+
189+
try {
190+
Class.forName("com.google.android.gms.common.GooglePlayServicesUtil");
191+
} catch (ClassNotFoundException e) {
192+
Log(LOG_LEVEL.FATAL, "The Google Play services client library was not found. Please make sure to include it in your project.", e, context);
193+
currentSubscription = -4;
194+
}
177195
}
178196

179197
try {
@@ -189,13 +207,6 @@ public static void init(Activity context, String googleProjectNumber, String one
189207
currentSubscription = -3;
190208
}
191209

192-
try {
193-
Class.forName("com.google.android.gms.common.GooglePlayServicesUtil");
194-
} catch (ClassNotFoundException e) {
195-
Log(LOG_LEVEL.FATAL, "The Google Play services client library was not found. Please make sure to include it in your project.", e, context);
196-
currentSubscription = -4;
197-
}
198-
199210
if (initDone) {
200211
if (context != null)
201212
appContext = context;
@@ -228,15 +239,6 @@ public static void init(Activity context, String googleProjectNumber, String one
228239
trackAmazonPurchase = new TrackAmazonPurchase(appContext);
229240
} catch (ClassNotFoundException e) {}
230241

231-
try {
232-
Class.forName("com.amazon.device.messaging.ADM");
233-
pushRegistrator = new PushRegistratorADM();
234-
deviceType = 2;
235-
} catch (ClassNotFoundException e) {
236-
pushRegistrator = new PushRegistratorGPS();
237-
deviceType = 1;
238-
}
239-
240242
// Re-register user if the app id changed, this might happen when a dev is testing.
241243
String oldAppId = getSavedAppId();
242244
if (oldAppId != null) {

0 commit comments

Comments
 (0)