Skip to content

Commit

Permalink
Merge pull request #1276 from OneSignal/fix/notif_open_cold_start_lau…
Browse files Browse the repository at this point in the history
…nch_activity

Fix notification open not launching main activity by default on app cold start
  • Loading branch information
jkasten2 committed Feb 5, 2021
2 parents 4b804ab + 14c340f commit 4eef232
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -2169,20 +2169,16 @@ static void applicationOpenedByNotification(@Nullable final String notificationI
sessionManager.onDirectInfluenceFromNotificationOpen(appEntryState, notificationId);
}

static boolean startOrResumeApp(Activity inContext) {
Intent launchIntent = inContext.getPackageManager().getLaunchIntentForPackage(inContext.getPackageName());
logger.debug("startOrResumeApp from context: " + inContext + " isRoot: " + inContext.isTaskRoot() + " with launchIntent: " + launchIntent);
// Make sure we have a launcher intent.
if (launchIntent != null) {
if (inContext.isTaskRoot()) {
inContext.startActivity(launchIntent);
} else {
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent.getActivity(inContext, 0, launchIntent, 0);
}
return true;
}
return false;
static boolean startOrResumeApp(Activity activity) {
Intent launchIntent = activity.getPackageManager().getLaunchIntentForPackage(activity.getPackageName());
logger.debug("startOrResumeApp from context: " + activity + " isRoot: " + activity.isTaskRoot() + " with launchIntent: " + launchIntent);

// Not all apps have a launcher intent, such as one that only provides a homescreen widget
if (launchIntent == null)
return false;

activity.startActivity(launchIntent);
return true;
}

/**
Expand Down

0 comments on commit 4eef232

Please sign in to comment.