17

I'm working on an application where I list the installed applications with the package manager. I can get the package name of the item clicked, but I'd like to then launch the details screen based on the package. So for instance if Dolphin Browser were selected in the list, you would then see the following image. How can I do this?

enter image description here

Final solution set your target as Gingerbread API level 9 and set your min as API level 7

final int apiLevel = Build.VERSION.SDK_INT;
Intent intent = new Intent();
if (apiLevel >= 9) {
    //TODO get working on gb
    //Toast.makeText(SDMove.this, "Gingerbread Not Currently Supported", Toast.LENGTH_LONG).show();
    startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                             Uri.parse("package:" + pli.pkg.packageName)));
} else {
    final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");
    intent.setAction(Intent.ACTION_VIEW);
    intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
    intent.putExtra(appPkgName, pli.pkg.packageName);
    startActivity(intent);
}

4 Answers 4

15

Try this:

startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:your.package.here")));

And replace "package:your.package.here" with the real package you want to view...

2
  • This answer is much better :) Aug 26, 2013 at 8:12
  • also, make sure to include the build variant if any. ex : Uri.parse("package:your.package.here."+BuildConfig.FLAVOR) Sep 14, 2022 at 4:02
12

Here is a fully working app with a ListActivity that lists all installed apps. When you click a package name, it opens the app details.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Intent for getting installed apps.
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    // Get installed apps
    List<ResolveInfo> appList = this.getPackageManager().queryIntentActivities(mainIntent, 0);

    // Make new list for package names and fill the list.
    List<String> packageNameList = new ArrayList<String>();
    for (ResolveInfo resolveInfo : appList) {
        packageNameList.add(resolveInfo.activityInfo.packageName);
    }

    // Set the list adapter.
    setListAdapter(new ArrayAdapter<String>(this, R.layout.simple, packageNameList));
}

public void onListItemClick(ListView l, View v, int position, long id)
{
    // Get the TextView that was clicked.
    TextView view = (TextView)v;

    // Get the text from the TextView.
    String packageName = (String)view.getText();

    // Open AppDetails for the selected package.
    showInstalledAppDetails(packageName);
}

public void showInstalledAppDetails(String packageName) {
    final int apiLevel = Build.VERSION.SDK_INT;
    Intent intent = new Intent();

    if (apiLevel >= 9) {
        intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + packageName));
    } else {
        final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");

        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        intent.putExtra(appPkgName, packageName);
    }

    // Start Activity
    startActivity(intent);
}

Remember to have main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView  
        android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>
    <TextView android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No apps installed"/>
</LinearLayout>

and simple.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
</TextView>

in your layout folder. Hope this works :)

10
  • Is there a manifest permission or something for this? i keep getting force closes with anything i try i just tried your method set it to something simple such as deskclock. I put your method in then ran showInstalledAppDetails("com.android.deskclock"); but no matter what i try it force closes i'm running project elite gb on a rooted d1 but the app i have set to 2.2 as my min sdk but no idea why i force close everytime
    – GFlam
    Jun 4, 2011 at 23:23
  • I got it to run on my 2.2 emulator, but when I tried "com.android.deskclock" I got "Exception when retrieving package: com.android.deskclock". Try another app, like "com.android.settings", that worked in the emulator. It is very important that the package name is right :) If you don't get it to work, you could post the stacktrace from LogCat.
    – khellang
    Jun 5, 2011 at 1:56
  • Yea just made a new project with 2.3 as the target this method force closes but the code below worked with 2.3 like you said but i need it on 2.2 since i'm writing this app for a 2.2 rom. Anyway posting the logcat in a second didn't see anything really in there but maybe you will
    – GFlam
    Jun 5, 2011 at 2:10
  • Java Code pastebin.com/cgjrAx2A Log Cat pastebin.com/P0e9XR4t error is at lines 98 and 99
    – GFlam
    Jun 5, 2011 at 2:13
  • I couldn't get the method above to work on my 2.3.3 phone, but on both the 2.2 and 2.3 emulator it worked :S But when I tried the first method on my phone it worked perfectly.. I'll have to look at it tomorrow
    – khellang
    Jun 5, 2011 at 3:00
3

To launch the app info setting for your app.

Uri uri = new Uri.Builder()
        .scheme("package")
        .opaquePart(getPackageName())
        .build();
startActivity(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri));
3

Here is the way to do it, this is a generic answer using build infos from your app. You have to use FLAG_ACTIVITY_NEW_TASK and build the right URI for your app.

  // Build intent that displays the App settings screen.
    Intent intent = new Intent();
                                intent.setAction(
    Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package",
            BuildConfig.APPLICATION_ID, null);
                                intent.setData(uri);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

You can use it from a snackbar for example.

Snackbar.make(
    findViewById(R.id.activity_layout),
    "snackbar text",
    Snackbar.LENGTH_INDEFINITE)
            .setAction("Settings", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Build intent that displays the App settings screen.
            Intent intent = new Intent();
            intent.setAction(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            Uri uri = Uri.fromParts("package",
                    BuildConfig.APPLICATION_ID, null);
            intent.setData(uri);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    })
            .show();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.