Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling an app from another app

In this app I'm developing I need to load/call another app that is already installed on the phone. It's an application for my own personal use only, so no need to check if the other app is installed - I know it is.

I've googled this problem for hours, but I can't find anything that works. Mostly because the guidelines for finding package name and class name are really bad.

Via cmd and adb I was able to find that the info regarding the application I'd like to call is: package:/data/app/com.soundcloud.android-1.apk=com.soundcloud.android (that's exactly what it said in the cmd window.)

I tried something like this:

Intent i = new Intent();
i.setClassName("/data/app/com.soundcloud.android-1.apk", "com.soundcloud.android");
startActivity(i);

But my app just crashes instead. I used the above code because someone said that this could call an app:

Intent i = new Intent();
i.setClassName("<package_name>","<Class Name(with package name)>");
startActivity(i);

Does anyone know what to really write?

P.S.: my own app does not need any information about what's happening in the called app.

like image 334
gosr Avatar asked Jan 12 '11 21:01

gosr


People also ask

How do you call one app from another app?

Intent i = new Intent(); i. setClassName("<package_name>","<Class Name(with package name)>"); startActivity(i);

How do you communicate between 2 different apps?

Android inter-process communication At the simplest level, there are two different ways for apps to interact on Android: via intents, passing data from one application to another; and through services, where one application provides functionality for others to use.

How do I call a method from another app on Android?

You cannot directly call a method of one app from another app. Instead, you have to invoke one activity from another and fetch result using Intent filters.

Can Android apps communicate with each other?

Android apps are screened for viruses and other security issues before being listed in the Google Play store, but only individually. Once downloaded, apps can communicate with each other without notifying the user.


2 Answers

Use the PackageManager to get an Intent for the package:

PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.example.package");
startActivity(intent);
like image 107
Ian G. Clifton Avatar answered Sep 30 '22 01:09

Ian G. Clifton


The documentation is here.

I think in your example, com.soundcloud.android is in fact the package name, so that should be the first argument. For the second one, you still need to figure out the class to use.

If you don't have the code, you can check how to find out the class from the apk with this.

like image 42
Matthieu Avatar answered Sep 30 '22 02:09

Matthieu