Search code examples
androidcallbackintentfilterurl-schemecustom-url

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


I saw in the post How to open an application inside another application within the latters boundaries in android?

But it is happening for my application, when I try to open another application with custom URL schemes. Does anyone know why this could be happening?

The code for calling the other application is as below.

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);

Solution

  • The reason was because, my application was a single task application. It is android property in the AndroidManifest.xml, of my activity element.

            android:launchMode="singleTask"
    

    The solution I found was to add two flags to the "redirectIntent".

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