How to launch another app from your app

If you ever need to launch another app from your own it’s actually easier than you think.
The PackageManager class provides some handy methods that make this a snap.
All you need to know is the package name of the app you want to launch and then use the code below:

protected void launchApp(String packageName) {
		Intent mIntent = getPackageManager().getLaunchIntentForPackage(
				packageName);
		if (mIntent != null) {
			try {
				startActivity(mIntent);
			} catch (ActivityNotFoundException err) {
				Toast t = Toast.makeText(getApplicationContext(),
						R.string.app_not_found, Toast.LENGTH_SHORT);
				t.show();
			}
		}
	}

You can use http://www.cyrket.com/ to get the package name of individual apps by looking at the url in the browser.

If you need to automate you can get a list of installed apps like this:

final PackageManager pm = getPackageManager();

		List packages = pm
				.getInstalledApplications(PackageManager.GET_META_DATA);

		for (ApplicationInfo packageInfo : packages) {

			Log.d(TAG, "Installed package :" + packageInfo.packageName);
			Log.d(TAG,
					"Launch Activity :"
							+ pm.getLaunchIntentForPackage(packageInfo.packageName));

		}

Hope this helps!

12 thoughts on “How to launch another app from your app

  1. In your second example (for the app list), do you really have to use the tag?

    Dympy

  2. Hi! I’m new to android so I have a question that is kind of related to your post. I have a list of all the installed apps on my phone. I used your code so as to when click on one item in the list it launches the application. My problem is that it works for some of the apps in the list ( I mean that it launches them)…but for some it tells me that the application has stopped unexpectedly and it is forced to close and it doesn’t launch it. Some of the apps that don’t work are Calculator, Contacts, Dialer, Example Wallpapers and some of the apps that work are Browser, Search, Music, Custom Locale a.s.o. I don’t know what the problem might be and maybe you have already encountered this problem and can enlighten me, I would be grateful!

  3. @Lacra & Pranay
    look under your manifest.xml
    u need to give android permission to use those features
    ex.

    there are a lot of others but i thought this would be of help

  4. uses-permission android:name=”android.permission.CALL_PHONE”
    uses-permission android:name=”android.permission.GET_TASKS”
    uses-permission android:name=”android.permission.READ_CONTACTS”
    uses-permission android:name=”android.permission.SET_WALLPAPER”
    uses-permission android:name=”android.permission.INTERNET”
    uses-permission android:name=”android.permission.EXPAND_STATUS_BAR”

  5. Hi all, my prob: I have a group of apps, when I launch each app in it, a message will appear and show the list of all of the other apps. I can click any app in this list and install it (if it isn’t installed) or launch it(if it is installed). I’m new to android, so, you can give me some advices?

  6. It is showing default apps present in your device for example: html viewer(com.android.htmlviewer),input device(com.android.inputdevices),key chain(com.android.keuchain) etc can you please help me

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>