java Android 启动应用程序详细信息页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6238946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:58:34  来源:igfitidea点击:

Android launch applications detail page

javaandroidandroid-intentdetails

提问by GFlam

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?

我正在开发一个应用程序,在其中使用包管理器列出已安装的应用程序。我可以点击项目的包名称,但我想然后根据包启动详细信息屏幕。例如,如果在列表中选择了 Dolphin Browser,您将看到下图。我怎样才能做到这一点?

enter image description here

在此处输入图片说明

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

最终解决方案将您的目标设置为GingerbreadAPI 级别 9,并将您的最小值设置为 API 级别 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);
}

采纳答案by khellang

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

这是一个功能齐全的应用程序,ListActivity其中列出了所有已安装的应用程序。当您单击包名称时,它会打开应用程序详细信息。

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:

记得有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:

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 layoutfolder. Hope this works :)

在您的布局文件夹中。希望这有效:)

回答by khellang

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

并将“package:your.package.here”替换为您要查看的真实包...

回答by Mathias Jeppsson

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