From eaabbe2c0e247fd7cf5a6fbbdf72f814f75cb14d Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Mon, 25 Oct 2021 12:40:11 -0700 Subject: [PATCH 1/6] Fix outside package target activities not opening This fix includes any launch URLs set to open the browser or another app The issue was due to an Activity backstack not being built correctly. Both `NotificationOpenedReceiver` and the target `Activity` were launched with `FLAG_ACTIVITY_NEW_TASK` however this means when `NotificationOpenedReceiver` is finished it does not bring up the target since it is on a different task. The Android flag `allowTaskReparenting` allows this to happen, however this can effect the backstack of the main task which we don't want to do. Setting `android:taskAffinity` does `FLAG_ACTIVITY_NEW_TASK` and `allowTaskReparenting` for us. By setting the value to "" (empty string) it prevents any side effects on existing tasks as it means it has no affinity to associate it with. This allowed us to clean up some runtime logic to add `FLAG_ACTIVITY_NEW_TASK` and others we no longer need now. --- OneSignalSDK/onesignal/src/main/AndroidManifest.xml | 1 + .../com/onesignal/GenerateNotificationOpenIntent.kt | 12 +----------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/OneSignalSDK/onesignal/src/main/AndroidManifest.xml b/OneSignalSDK/onesignal/src/main/AndroidManifest.xml index 8cdd87ecc0..1f3dc2aae9 100644 --- a/OneSignalSDK/onesignal/src/main/AndroidManifest.xml +++ b/OneSignalSDK/onesignal/src/main/AndroidManifest.xml @@ -136,6 +136,7 @@ android:name="com.onesignal.NotificationOpenedReceiver" android:noHistory="true" android:excludeFromRecents="true" + android:taskAffinity="" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="true" /> diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt index db6faefc37..c838cadab8 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt @@ -17,19 +17,9 @@ class GenerateNotificationOpenIntent( ): Intent { // We use SINGLE_TOP and CLEAR_TOP as we don't want more than one OneSignal invisible click // tracking Activity instance around. - var intentFlags = + val intentFlags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP - if (!startApp) { - // If we don't want the app to launch we put OneSignal's invisible click tracking Activity on it's own task - // so it doesn't resume an existing one once it closes. - intentFlags = - intentFlags or ( - Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_ACTIVITY_MULTIPLE_TASK or - Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET - ) - } return Intent( context, From c28ed78cc1ad3a9be04c6d4e321ca2326a092eb1 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Mon, 25 Oct 2021 20:58:58 -0700 Subject: [PATCH 2/6] Fix Android 5.1 and older not resuming app App would not resume on Android 5 after the `taskAffinity=""` addition added in the last commit. This seems to be an issue with allowTaskReparenting not working in this case. Even explicitly enabling it did not work. `taskAffinity` is required for newer vesions of Android to correctly start a new task and to reparent it to the correct task. This is why two different implementations had to be added. --- .../onesignal/src/main/AndroidManifest.xml | 6 ++ .../GenerateNotificationOpenIntent.kt | 44 +++++++++++--- ...cationOpenedReceiverAndroid22AndOlder.java | 60 +++++++++++++++++++ .../onesignal/GenerateNotificationRunner.java | 2 +- 4 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.java diff --git a/OneSignalSDK/onesignal/src/main/AndroidManifest.xml b/OneSignalSDK/onesignal/src/main/AndroidManifest.xml index 1f3dc2aae9..91482c8b43 100644 --- a/OneSignalSDK/onesignal/src/main/AndroidManifest.xml +++ b/OneSignalSDK/onesignal/src/main/AndroidManifest.xml @@ -140,6 +140,12 @@ android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="true" /> + diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt index c838cadab8..cebc35b706 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt @@ -10,26 +10,56 @@ class GenerateNotificationOpenIntent( private val startApp: Boolean ) { - private val notificationOpenedClass: Class<*> = NotificationOpenedReceiver::class.java + private val notificationOpenedClassAndroid23Plus: Class<*> = NotificationOpenedReceiver::class.java + private val notificationOpenedClassAndroid22AndOlder: Class<*> = NotificationOpenedReceiverAndroid22AndOlder::class.java fun getNewBaseIntent( notificationId: Int, ): Intent { + val intent = + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) + getNewBaseIntentAndroidAPI23Plus() + else + getNewBaseIntentAndroidAPI22AndOlder() + + return intent + .putExtra( + GenerateNotification.BUNDLE_KEY_ANDROID_NOTIFICATION_ID, + notificationId + ) // We use SINGLE_TOP and CLEAR_TOP as we don't want more than one OneSignal invisible click // tracking Activity instance around. - val intentFlags = + .addFlags( Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP + ) + } + private fun getNewBaseIntentAndroidAPI23Plus(): Intent { return Intent( context, - notificationOpenedClass + notificationOpenedClassAndroid23Plus ) - .putExtra( - GenerateNotification.BUNDLE_KEY_ANDROID_NOTIFICATION_ID, - notificationId + } + + // See NotificationOpenedReceiverAndroid22AndOlder.java for details + private fun getNewBaseIntentAndroidAPI22AndOlder(): Intent { + val intent = Intent( + context, + notificationOpenedClassAndroid22AndOlder ) - .addFlags(intentFlags) + + if (getIntentVisible() == null) { + // If we don't show a visible Activity put OneSignal's invisible click tracking + // Activity on it's own task so it doesn't resume an existing one once it closes. + intent.addFlags( + Intent.FLAG_ACTIVITY_NEW_TASK or + Intent.FLAG_ACTIVITY_MULTIPLE_TASK or + Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET + ) + } + + return intent } /** diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.java new file mode 100644 index 0000000000..0555bae671 --- /dev/null +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.java @@ -0,0 +1,60 @@ +/** + * Modified MIT License + * + * Copyright 2021 OneSignal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 2. All copies of substantial portions of the Software may only be used in connection + * with services provided by OneSignal. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.onesignal; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; + +/** + * This is the same as NotificationOpenedReceiver expect it doesn't contain + * android:taskAffinity="" in it's AndroidManifest.xml entry. This is to + * account for the resume behavior not working on Android API 22 and older. + * + * In Android 5.x and older, android:taskAffinity="" starts a new task as + * expected, however the allowTaskReparenting behavior does not happen which + * results in the app not resuming, when using reverse Activity trampoline. + * Oddly enough cold starts of the app were not a problem. + */ +public class NotificationOpenedReceiverAndroid22AndOlder extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + NotificationOpenedProcessor.processFromContext(this, getIntent()); + finish(); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + NotificationOpenedProcessor.processFromContext(this, getIntent()); + finish(); + } + +} \ No newline at end of file diff --git a/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java b/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java index 97f320924b..4a54d6a110 100644 --- a/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java +++ b/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java @@ -1180,7 +1180,7 @@ private void generateNotificationWithLaunchURL() throws Exception { } private void assertNotificationOpenedReceiver(@NonNull Intent intent) { - assertEquals("com.onesignal.NotificationOpenedReceiver", intent.getComponent().getClassName()); + assertEquals(com.onesignal.NotificationOpenedReceiverAndroid22AndOlder.class.getName(), intent.getComponent().getClassName()); } private void assertOpenMainActivityIntent(@NonNull Intent intent) { From c988d12e57a1ae9a9bb34183a1a954a21e3dce4f Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Wed, 27 Oct 2021 13:25:34 -0700 Subject: [PATCH 3/6] Add deprecated and requiresApi annotations This is to flag that these should be cleaned up when support for Android API 22 and older is dropped. --- .../main/java/com/onesignal/GenerateNotificationOpenIntent.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt index cebc35b706..1d6efaf11a 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt @@ -3,6 +3,7 @@ package com.onesignal import android.app.PendingIntent import android.content.Context import android.content.Intent +import androidx.annotation.RequiresApi class GenerateNotificationOpenIntent( private val context: Context, @@ -35,6 +36,7 @@ class GenerateNotificationOpenIntent( ) } + @RequiresApi(android.os.Build.VERSION_CODES.M) private fun getNewBaseIntentAndroidAPI23Plus(): Intent { return Intent( context, @@ -43,6 +45,7 @@ class GenerateNotificationOpenIntent( } // See NotificationOpenedReceiverAndroid22AndOlder.java for details + @Deprecated("Use getNewBaseIntentAndroidAPI23Plus instead for Android 6+") private fun getNewBaseIntentAndroidAPI22AndOlder(): Intent { val intent = Intent( context, From 00f1367872aa1108db67a2d52666963baf6989af Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Wed, 27 Oct 2021 14:13:35 -0700 Subject: [PATCH 4/6] Covert NotificationOpenReceivers to Kotlin Ran the auto convert in Android Studio and updated comment in code --- .../GenerateNotificationOpenIntent.kt | 2 +- ...ver.java => NotificationOpenedReceiver.kt} | 35 ++++++++----------- ...icationOpenedReceiverAndroid22AndOlder.kt} | 31 +++++++--------- 3 files changed, 29 insertions(+), 39 deletions(-) rename OneSignalSDK/onesignal/src/main/java/com/onesignal/{NotificationOpenedReceiver.java => NotificationOpenedReceiver.kt} (69%) rename OneSignalSDK/onesignal/src/main/java/com/onesignal/{NotificationOpenedReceiverAndroid22AndOlder.java => NotificationOpenedReceiverAndroid22AndOlder.kt} (78%) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt index 1d6efaf11a..8fb46098bd 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotificationOpenIntent.kt @@ -44,7 +44,7 @@ class GenerateNotificationOpenIntent( ) } - // See NotificationOpenedReceiverAndroid22AndOlder.java for details + // See NotificationOpenedReceiverAndroid22AndOlder.kt for details @Deprecated("Use getNewBaseIntentAndroidAPI23Plus instead for Android 6+") private fun getNewBaseIntentAndroidAPI22AndOlder(): Intent { val intent = Intent( diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.kt similarity index 69% rename from OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.java rename to OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.kt index 4fc18fd5e3..a98f09294e 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.kt @@ -24,27 +24,22 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +package com.onesignal -package com.onesignal; +import android.app.Activity +import android.content.Intent +import android.os.Bundle -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; - -public class NotificationOpenedReceiver extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - NotificationOpenedProcessor.processFromContext(this, getIntent()); - finish(); - } - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - NotificationOpenedProcessor.processFromContext(this, getIntent()); - finish(); - } +class NotificationOpenedReceiver : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + NotificationOpenedProcessor.processFromContext(this, intent) + finish() + } + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + NotificationOpenedProcessor.processFromContext(this, getIntent()) + finish() + } } \ No newline at end of file diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt similarity index 78% rename from OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.java rename to OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt index 0555bae671..f1953e1d69 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt @@ -24,12 +24,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +package com.onesignal -package com.onesignal; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; +import android.app.Activity +import android.content.Intent +import android.os.Bundle /** * This is the same as NotificationOpenedReceiver expect it doesn't contain @@ -41,20 +40,16 @@ * results in the app not resuming, when using reverse Activity trampoline. * Oddly enough cold starts of the app were not a problem. */ -public class NotificationOpenedReceiverAndroid22AndOlder extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - NotificationOpenedProcessor.processFromContext(this, getIntent()); - finish(); +class NotificationOpenedReceiverAndroid22AndOlder : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + NotificationOpenedProcessor.processFromContext(this, intent) + finish() } - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - NotificationOpenedProcessor.processFromContext(this, getIntent()); - finish(); + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + NotificationOpenedProcessor.processFromContext(this, getIntent()) + finish() } - } \ No newline at end of file From 86522908e234da4ddaae40d4f345d64ba4c62a8c Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Wed, 27 Oct 2021 15:04:13 -0700 Subject: [PATCH 5/6] Test ensuring correct Activity is used for API Add test to ensure correct Activity is for Notification opens when device is running Android API 23 (Android 6) or newer. --- .../onesignal/GenerateNotificationRunner.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java b/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java index 4a54d6a110..ad2212e423 100644 --- a/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java +++ b/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java @@ -1130,6 +1130,21 @@ public void shouldSetButtonsCorrectly() throws Exception { assertEquals("id1", new JSONObject(json_data).optString(BUNDLE_KEY_ACTION_ID)); } + @Test + @Config(sdk = 23, shadows = { ShadowGenerateNotification.class }) + public void shouldUseCorrectActivityForAndroid23Plus() throws Exception { + NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, getBaseNotifBundle()); + threadAndTaskWait(); + + Intent[] intents = lastNotificationIntents(); + assertEquals("android.intent.action.MAIN", intents[0].getAction()); + assertEquals( + com.onesignal.NotificationOpenedReceiver.class.getName(), + intents[1].getComponent().getClassName() + ); + assertEquals(2, intents.length); + } + @Test @Config(shadows = { ShadowGenerateNotification.class }) public void shouldSetContentIntentForLaunchURL() throws Exception { From 17f63402f9504ee12dbf83518dee70fd726ec722 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Mon, 1 Nov 2021 16:36:23 -0700 Subject: [PATCH 6/6] abstract class to share NotificationOpenedReceiver Created abstract NotificationOpenedReceiverBase to share code between both activities. It is very unlikly the code would ever be different between them and prevents possible future mistakes of editing only one. --- .../onesignal/NotificationOpenedReceiver.kt | 20 +-------- ...ficationOpenedReceiverAndroid22AndOlder.kt | 18 +------- .../NotificationOpenedReceiverBase.kt | 45 +++++++++++++++++++ 3 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverBase.kt diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.kt index a98f09294e..c3d29de7bb 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.kt +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiver.kt @@ -1,7 +1,7 @@ /** * Modified MIT License * - * Copyright 2017 OneSignal + * Copyright 2021 OneSignal * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,20 +26,4 @@ */ package com.onesignal -import android.app.Activity -import android.content.Intent -import android.os.Bundle - -class NotificationOpenedReceiver : Activity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - NotificationOpenedProcessor.processFromContext(this, intent) - finish() - } - - override fun onNewIntent(intent: Intent) { - super.onNewIntent(intent) - NotificationOpenedProcessor.processFromContext(this, getIntent()) - finish() - } -} \ No newline at end of file +class NotificationOpenedReceiver : NotificationOpenedReceiverBase() diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt index f1953e1d69..9f446b063a 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt @@ -26,10 +26,6 @@ */ package com.onesignal -import android.app.Activity -import android.content.Intent -import android.os.Bundle - /** * This is the same as NotificationOpenedReceiver expect it doesn't contain * android:taskAffinity="" in it's AndroidManifest.xml entry. This is to @@ -40,16 +36,4 @@ import android.os.Bundle * results in the app not resuming, when using reverse Activity trampoline. * Oddly enough cold starts of the app were not a problem. */ -class NotificationOpenedReceiverAndroid22AndOlder : Activity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - NotificationOpenedProcessor.processFromContext(this, intent) - finish() - } - - override fun onNewIntent(intent: Intent) { - super.onNewIntent(intent) - NotificationOpenedProcessor.processFromContext(this, getIntent()) - finish() - } -} \ No newline at end of file +class NotificationOpenedReceiverAndroid22AndOlder : NotificationOpenedReceiverBase() diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverBase.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverBase.kt new file mode 100644 index 0000000000..585c650e2f --- /dev/null +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverBase.kt @@ -0,0 +1,45 @@ +/** + * Modified MIT License + * + * Copyright 2021 OneSignal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 2. All copies of substantial portions of the Software may only be used in connection + * with services provided by OneSignal. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.onesignal + +import android.app.Activity +import android.content.Intent +import android.os.Bundle + +abstract class NotificationOpenedReceiverBase : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + NotificationOpenedProcessor.processFromContext(this, intent) + finish() + } + + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + NotificationOpenedProcessor.processFromContext(this, getIntent()) + finish() + } +} \ No newline at end of file