@@ -2394,7 +2394,7 @@ static void fireForegroundHandlers(OSNotificationController notificationControll
2394
2394
/**
2395
2395
* Method called when opening a notification
2396
2396
*/
2397
- static void handleNotificationOpen (final Activity context , final JSONArray data , final boolean startLauncherActivity , @ Nullable final String notificationId ) {
2397
+ static void handleNotificationOpen (final Activity context , final JSONArray data , @ Nullable final String notificationId ) {
2398
2398
// Delay call until remote params are set
2399
2399
if (taskRemoteController .shouldQueueTaskForInit (OSTaskRemoteController .HANDLE_NOTIFICATION_OPEN )) {
2400
2400
logger .error ("Waiting for remote params. " +
@@ -2404,7 +2404,7 @@ static void handleNotificationOpen(final Activity context, final JSONArray data,
2404
2404
public void run () {
2405
2405
if (appContext != null ) {
2406
2406
logger .debug ("Running " + OSTaskRemoteController .HANDLE_NOTIFICATION_OPEN + " operation from pending queue." );
2407
- handleNotificationOpen (context , data , startLauncherActivity , notificationId );
2407
+ handleNotificationOpen (context , data , notificationId );
2408
2408
}
2409
2409
}
2410
2410
});
@@ -2422,39 +2422,35 @@ public void run() {
2422
2422
2423
2423
if (shouldInitDirectSessionFromNotificationOpen (context , data )) {
2424
2424
applicationOpenedByNotification (notificationId );
2425
-
2426
- if (startLauncherActivity ) {
2427
- // Start activity with an activity trampolining
2428
- startOrResumeApp (context );
2429
- }
2430
2425
}
2431
2426
2427
+ openDestinationActivity (context , data );
2428
+
2432
2429
runNotificationOpenedCallback (data );
2433
2430
}
2434
2431
2435
- // Reverse activity trampolining is used for most notifications.
2436
- // This method is only used if the push provider does support it.
2437
- // This opens the app in the same way an Android home screen launcher does.
2438
- // This means we expect the following behavior:
2439
- // 1. Starts the Activity defined in the app's AndroidManifest.xml as "android.intent.action.MAIN"
2440
- // 2. If the app is already running, instead the last activity will be resumed
2441
- // 3. If the app is not running (due to being push out of memory), the last activity will be resumed
2442
- // 4. If the app is no longer in the recent apps list, it is not resumed, same as #1 above.
2443
- // - App is removed from the recent app's list if it is swiped away or "clear all" is pressed.
2444
- static boolean startOrResumeApp (@ NonNull Activity activity ) {
2445
- Intent launchIntent = activity .getPackageManager ().getLaunchIntentForPackage (activity .getPackageName ());
2446
- logger .debug ("startOrResumeApp from context: " + activity + " isRoot: " + activity .isTaskRoot () + " with launchIntent: " + launchIntent );
2447
-
2448
- // Not all apps have a launcher intent, such as one that only provides a homescreen widget
2449
- if (launchIntent == null )
2450
- return false ;
2451
- // Removing package from the intent, this treats the app as if it was started externally.
2452
- // This gives us the resume app behavior noted above.
2453
- // Android 11 no longer requires nulling this out to get this behavior.
2454
- launchIntent .setPackage (null );
2455
-
2456
- activity .startActivity (launchIntent );
2457
- return true ;
2432
+ static private void openDestinationActivity (
2433
+ @ NonNull final Activity activity ,
2434
+ @ NonNull final JSONArray pushPayloads
2435
+ ) {
2436
+ try {
2437
+ // Always use the top most notification if user tapped on the summary notification
2438
+ JSONObject firstPayloadItem = pushPayloads .getJSONObject (0 );
2439
+ GenerateNotificationOpenIntent intentGenerator = GenerateNotificationOpenIntentFromPushPayload .INSTANCE .create (
2440
+ activity ,
2441
+ firstPayloadItem
2442
+ );
2443
+
2444
+ Intent intent = intentGenerator .getIntentVisible ();
2445
+ if (intent != null ) {
2446
+ activity .startActivity (intent );
2447
+ }
2448
+ else {
2449
+ logger .info ("SDK not showing an Activity automatically due to it's settings." );
2450
+ }
2451
+ } catch (JSONException e ) {
2452
+ e .printStackTrace ();
2453
+ }
2458
2454
}
2459
2455
2460
2456
private static boolean shouldInitDirectSessionFromNotificationOpen (Activity context , final JSONArray data ) {
0 commit comments