mirror of
https://github.com/status-im/react-native.git
synced 2025-02-15 19:06:41 +00:00
Launch a new task if openURL is called with a url in a different package
Summary: Change the default handling of openURL to attach the NEW_TASK flag if the package we will be launching is different than the currently running package. Reviewed By: foghina Differential Revision: D2977441 fb-gh-sync-id: 01d1ac1d791345f815bfc9e8358bce6420c08c1b shipit-source-id: 01d1ac1d791345f815bfc9e8358bce6420c08c1b
This commit is contained in:
parent
b860897cd5
commit
542432fc3e
@ -10,6 +10,7 @@
|
||||
package com.facebook.react.modules.intent;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
@ -80,9 +81,20 @@ public class IntentModule extends ReactContextBaseJavaModule {
|
||||
Activity currentActivity = getCurrentActivity();
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
|
||||
String selfPackageName = getReactApplicationContext().getPackageName();
|
||||
ComponentName componentName = intent.resolveActivity(
|
||||
getReactApplicationContext().getPackageManager());
|
||||
String otherPackageName = (componentName != null ? componentName.getPackageName() : "");
|
||||
|
||||
// Always add the FLAG_ACTIVITY_NEW_TASK if we are launching to a different package
|
||||
if (!selfPackageName.equals(otherPackageName)) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
||||
if (currentActivity != null) {
|
||||
currentActivity.startActivity(intent);
|
||||
} else {
|
||||
// If no currentActivity, we want to always start a new task regardless of logic above
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
getReactApplicationContext().startActivity(intent);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user