7

I want to call one android application from another application

I have tried some examples, but they are not working for me, I'm getting a Package parse error.

Consider there are two applications: Application1 and Application2

I want to call Application2 from Application1

Here is the some sample code to do this:

Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(fileName),"application/vnd.android.package-archive"); 
startActivity(i);

Here fileName = "file://data/data/package_name/files/Application1.apk";

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
Akshata
  • 271
  • 2
  • 7
  • 11
  • 2
    There are many concepts in Android that resemble "call one android application from another". Please consider adding another hundred words or so to your question, explaining what it is you are trying to accomplish, so we can help you better. – CommonsWare Apr 28 '10 at 11:55
  • Possible duplicate of [Launch an application from another application on Android](http://stackoverflow.com/questions/3872063/launch-an-application-from-another-application-on-android) – galacticninja Feb 27 '16 at 17:50

4 Answers4

6

I think this code will help:

Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);

if(list.size() > 0)
{
 Log.i("Log", "Have application" + list.size());
 startActivity(intent);
}
else
{
    Log.i("Log", "None application");
}
Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
Saio
  • 61
  • 1
  • 2
1

Are you trying to launch an application that is not installed? It looks like you're trying to execute an app by passing app1 the location of the .apk file for app2 on the sd card - this won't work. The Android OS will know how to invoke app2 via Intents only after the user has installed it (consider the security risks if you could just invoke any arbitrary code sitting on the sd card).

Assuming app1 and app2 are installed, look at the AndroidManifest.xml file for app2. This file will indicate what kind of Intents it will respond to.

see http://developer.android.com/guide/topics/intents/intents-filters.html#npex for a good example.

Please show us the AndroidManifest.xml file for app2 if you need more help.

Keith
  • 2,958
  • 4
  • 26
  • 29
0
Intent i4=new Intent(Intent.ACTION_MAIN);

PackageManager manager = getPackageManager();

i4 = manager.getLaunchIntentForPackage("com.apk");//apk name

i4.addCategory(Intent.CATEGORY_LAUNCHER);

startActivity(i4);
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
Khushi
  • 147
  • 1
  • 8
0
private void handleCallGooglePlay(Activity mActivity, String packageClass) {
        try {
            mActivity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + packageClass)));
        } catch (Exception var4) {
            mActivity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(package_name)));  //package name
        }
    }
Perazim
  • 1,501
  • 3
  • 19
  • 42
Tan Lee
  • 1
  • 1