Home > OS >  Programmatically open an external app in Android
Programmatically open an external app in Android

Time:11-03

One can open an external app like this:

myIntent = Intent(Intent.ACTION_VIEW)
startActivity(myIntent)

which opens the external app in full screen without an obvious way for the user to return to the original app.

In iOS when you open the SMS app using MFMessageComposeViewController it comes up as a popup. Once the user dismisses the SMS app they are automatically back in the original app.

Is there a way to do this in Android?

CodePudding user response:

SDK > 30 (Android 11) add this to your manifest:

<queries>
    <package android:name="com.package.name" />
</queries>

After that you can simply do:

Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage("com.package.name");
startActivity(intent);

EDIT:

If the user has put the device into a multi-window mode, you can use FLAG_ACTIVITY_LAUNCH_ADJACENT to try to launch the other activity into a separate window.

  • Related