1

i want to open another installed app such as Pandora from my app.

Here is the code:

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("Pandora");
    startActivity(LaunchIntent);

The above crashes my code, can someone provide code correction please?

Thank you in advance.

4 Answers4

0

You are just firing up intent and say to OS that you would like some application to open and display file located at path. Android will choice suitable application for you (or ask user to choose one of available apps)

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
0

I believe you are trying to open a PDF viewer. What you need is not the path to any apk, but the path to the PDF file you want to open. Android system will automatically figure out which application to invoke for the arguments specified in the intent.

Sameer
  • 4,379
  • 1
  • 23
  • 23
0

I think what you want to do is call the application by its packet name (you need to figure that out, but that should be easy)

PackageManager pm = getPackageManager();
try {
String packageName = "com.example.package";
Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
startActivity(launchIntent);
}
catch (Exception e1){}

That should open the other application if it is installed.

  • what is the best way to determine packageName, i tired Pandora & Pandora.apk but has not opened.. Any idea? – user1082770 Oct 06 '12 at 16:54
  • To open the Pandora application the packet name should be "com.pandora.android" if I'm not mistaken and we're talking about the same application. (Can't check from here as the application is not available in most countries) – user1542836 Oct 06 '12 at 16:54
0
File yourApk= new File("/sdcard/.../pandora.apk");
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(yourApk), "application/vnd.android.package-archive");
startActivity(i);

permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>
Tamir Scherzer
  • 995
  • 8
  • 8