开发者

Android launch applications detail page

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?

Android launch applications detail page

Final solution set your target as Gingerbread API level 9 and set your min as A开发者_如何学CPI 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);
}


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...


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 :)


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));


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜