Search code examples
androidnulllauncher

Launch app using package name


I am trying to launch an application from my own application in Android. What i have done is get all the package names of the apps installed into the device and stored them into a String Array. Then with a list view i try to launch every app selected.

In order to create a new intent to launch every app i use the following code claimed to work in several posts in android tutorial sites:

Intent intent = packageManager.getLaunchIntentForPackage(packages[arg2]);

where packages is the name of my table containing the package names and arg2 the listview selected item.

The problem is that even if i check with toast messages i can see the package name is correct but the getLaunchIntentForPackage is always null and the apps are not starting.

Thanks


Solution

  • Try this :

    String pack[] = {"com.android.setting", "com.android.browser"};     
    try {
        Intent intent = getPackageManager().getLaunchIntentForPackage(pack[0]);
        startActivity(intent);
    } catch (Exception e) {
        // returns null if application is not installed
    }