使用自定义 URL 方案启动另一个应用程序会在启动应用程序的边界内打开该应用程序。

Launching another application using custom URL scheme opens the application within the boundaries of the launching application.

我在postHow to open an application inside another application within the latters boundaries in android?

看到了

但是当我尝试打开另一个具有自定义 URL 方案的应用程序时,我的应用程序正在发生这种情况。有谁知道为什么会这样?

调用对方应用的代码如下

String callBackUrl = “OtherApp://result?params”; // This is supposed to be a callback URL with query parameters
String redirectUrl = callBackUrl.substring(0, callBackUrl.indexOf("://"));
Intent redirectIntent = new Intent();
redirectIntent.putExtra(Intent.EXTRA_TEXT, callBackUrl);
redirectIntent.setAction(redirectUrl);
redirectIntent.setType("text/plain");
startActivity(redirectIntent);

原因是,我的应用程序是单任务应用程序。它是我的 activity 元素的 AndroidManifest.xml 中的 android 属性。

        android:launchMode="singleTask"

我找到的解决方案是向 "redirectIntent" 添加两个标志。

        redirectIntent.setFlags(Intent.URI_INTENT_SCHEME);
        redirectIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);