Android: How to Open Another App from My App

how to open other app activity from myapp?

Your package and class names do not match. Based on the manifest of the app you want to start, you need to change this:

intent.setClassName("com.rayvatapps.flatplan", "com.rayvatapps.flatplan.LoginActivity");

into this:

intent.setClassName("com.rayvatapps.flatmaps", "com.rayvatapps.flatmaps.LoginActivity");

You also don't need the <intent-filter> on the Activity in the app you are trying to start, as you are using an explicit Intent to start it. If you remove the <intent-filter> make sure that you keep the android:exported="true" for the Activity, otherwise you won't be able to launch it from another application.

Open another application from your own (intent)

Firstly, the concept of "application" in Android is slightly an extended one.

An application - technically a process - can have multiple activities, services, content providers and/or broadcast listeners. If at least one of them is running, the application is up and running (the process).

So, what you have to identify is how do you want to "start the application".

Ok... here's what you can try out:

  1. Create an intent with action=MAIN and category=LAUNCHER
  2. Get the PackageManager from the current context using context.getPackageManager
  3. packageManager.queryIntentActivity(<intent>, 0) where intent has category=LAUNCHER, action=MAIN or packageManager.resolveActivity(<intent>, 0) to get the first activity with main/launcher
  4. Get theActivityInfo you're interested in
  5. From the ActivityInfo, get the packageName and name
  6. Finally, create another intent with with category=LAUNCHER, action=MAIN, componentName = new ComponentName(packageName, name) and setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  7. Finally, context.startActivity(newIntent)

How to launch an Activity from another Application in Android 30

Android 11 added restrictions regarding the visibility of other apps. Apps that have targetSdk set to >= 30 can't interact with and open other apps without specifying this in the manifest.

To specify that your app interacts with another specific app, you need to add a <queries> element to your manifest file:

<manifest package="com.example.game">
<queries>
<package android:name="com.android.audioapp" />
</queries>
...
</manifest>

The link below contains other examples in case you need to specify a broader range of apps which you want to interact with.

Source: https://developer.android.com/training/basics/intents/package-visibility

android: how do i open another app from my app?

How to see if Intent is available:

  1. Try calling Intent and deal with ActivityNotFoundException if it isn't available

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(path, "application/pdf");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    try {
    startActivity(intent);
    }
    catch (ActivityNotFoundException e) {
    Toast.makeText(OpenPdf.this,
    "No Application Available to View PDF",
    Toast.LENGTH_SHORT).show();
    }

    or

  2. Query the Package Manager to see if it is ahead of time:

    PackageManager packageManager = getPackageManager();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setType("application/pdf");

    List list = packageManager.queryIntentActivities(intent,
    PackageManager.MATCH_DEFAULT_ONLY);

    if (list.size() > 0) {
    intent.setDataAndType(path, "application/pdf");
    startActivity(intent);
    }

How to pass parameters to an application or know its capabilities:

  1. List of Available Intents for Google Applications
  2. List of Intents by 3rd parties @ OpenIntents

Android- launch another app from activity

I found the solution. In the manifest file of the application
I found My package name: com.package.address and the name of the Mainctivity which I want to launch:

The following code starts this application:

  Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);


Related Topics



Leave a reply



Submit