Skip to content

Commit 7b905fb

Browse files
author
Vivek Ayer
committed
Merge pull request #22 from one-signal/fix_for_launch_url_when_app_is_closed
URLs now launch when app is closed and init is in an Activity
2 parents 30e198c + 64f6917 commit 7b905fb

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

OneSignalSDK/app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ dependencies {
5959
//compile "com.google.android.gms:play-services-analytics:7.0.0"
6060
compile "com.google.android.gms:play-services-location:8.4.0"
6161

62-
// testCompile 'junit:junit:4.12'
62+
testCompile 'junit:junit:4.12'
6363
// testCompile 'org.robolectric:shadows-support-v4:3.0'
64-
// testCompile('org.robolectric:robolectric:3.0') {
65-
// exclude group: 'commons-logging', module: 'commons-logging'
66-
// exclude group: 'org.apache.httpcomponents', module: 'httpclient'
67-
// }
68-
69-
testCompile("org.robolectric:robolectric:3.1-SNAPSHOT") {
64+
testCompile('org.robolectric:robolectric:3.0') {
65+
exclude group: 'commons-logging', module: 'commons-logging'
7066
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
7167
}
68+
69+
// testCompile("org.robolectric:robolectric:3.1-SNAPSHOT") {
70+
// exclude group: 'org.apache.httpcomponents', module: 'httpclient'
71+
// }
7272
}

OneSignalSDK/app/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,21 @@ public void testOpeningLauncherActivity() throws Exception {
242242
Assert.assertNull(Shadows.shadowOf(blankActivity).getNextStartedActivity());
243243
}
244244

245+
@Test
246+
public void testOpeningLaunchUrl() throws Exception {
247+
// Clear app launching normally
248+
Shadows.shadowOf(blankActivity).getNextStartedActivity();
249+
250+
// No OneSignal init here to test case where it is located in an Activity.
251+
252+
OneSignal.handleNotificationOpened(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\", \"u\": \"http://google.com\" } }]"), false);
253+
254+
Intent intent = Shadows.shadowOf(blankActivity).getNextStartedActivity();
255+
Assert.assertEquals("android.intent.action.VIEW", intent.getAction());
256+
Assert.assertEquals("http://google.com", intent.getData().toString());
257+
Assert.assertNull(Shadows.shadowOf(blankActivity).getNextStartedActivity());
258+
}
259+
245260
@Test
246261
public void testDisableOpeningLauncherActivityOnNotifiOpen() throws Exception {
247262
ShadowApplication.getInstance().getAppManifest().getApplicationMetaData().put("com.onesignal.NotificationOpened.DEFAULT", "DISABLE");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static void sendPurchases(JSONArray purchases, boolean newAsExisting, OneSignalR
820820
}
821821
}
822822

823-
private static boolean openURLFromNotification(JSONArray dataArray) {
823+
private static boolean openURLFromNotification(Context context, JSONArray dataArray) {
824824
int jsonArraySize = dataArray.length();
825825

826826
boolean urlOpened = false;
@@ -840,7 +840,7 @@ private static boolean openURLFromNotification(JSONArray dataArray) {
840840

841841
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
842842
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
843-
appContext.startActivity(intent);
843+
context.startActivity(intent);
844844
urlOpened = true;
845845
}
846846
} catch (Throwable t) {
@@ -943,7 +943,7 @@ static void handleNotificationOpened(JSONArray data) {
943943
public static void handleNotificationOpened(Context inContext, JSONArray data, boolean fromAlert) {
944944
sendNotificationOpened(inContext, data);
945945

946-
boolean urlOpened = openURLFromNotification(data);
946+
boolean urlOpened = openURLFromNotification(inContext, data);
947947

948948
runNotificationOpenedCallback(data, false);
949949

0 commit comments

Comments
 (0)