【问题标题】:Android launch applications detail pageAndroid 启动应用程序详细信息页面
【发布时间】:2011-06-04 19:37:59
【问题描述】:

我正在开发一个应用程序,在该应用程序中我使用包管理器列出已安装的应用程序。我可以获取单击项目的包名称,但我想随后根据包启动详细信息屏幕。因此,例如,如果在列表中选择了 Dolphin Browser,您将看到以下图像。我该怎么做?

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

【问题讨论】:

    标签: java android android-intent


    【解决方案1】:

    试试这个:

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

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

    【讨论】:

    • 这个答案好多了:)
    【解决方案2】:

    这是一个功能齐全的应用程序,其 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);
    }
    

    记得有ma​​in.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>
    

    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>
    

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

    【讨论】:

    • 是否有清单许可或其他什么?我尝试用任何东西都会强制关闭我只是尝试了您的方法,将其设置为简单的东西,例如桌面时钟。我把你的方法放进去,然后运行 ​​showInstalledAppDetails("com.android.deskclock");但无论我尝试什么强制关闭我都在根 d1 上运行 project elite gb 但我已将应用程序设置为 2.2 作为我的 min sdk 但不知道为什么我每次都强制关闭
    • 我让它在我的 2.2 模拟器上运行,但是当我尝试“com.android.deskclock”时,我得到“检索包时出现异常:com.android.deskclock”。尝试在模拟器中运行的另一个应用程序,例如“com.android.settings”。正确的包名称非常重要:) 如果你不能让它工作,你可以从 LogCat 发布堆栈跟踪。
    • 是的,刚刚创建了一个以 2.3 为目标的新项目,此方法强制关闭,但下面的代码像你说的那样与 2.3 一起工作,但我需要在 2.2 上使用它,因为我正在为 2.2 rom 编写这个应用程序.无论如何,在一秒钟内发布 logcat 并没有看到任何东西,但也许你会
    • Java 代码 pastebin.com/cgjrAx2A Log Cat pastebin.com/P0e9XR4t 错误在第 98 行和第 99 行
    • 我无法让上述方法在我的 2.3.3 手机上运行,​​但在 2.2 和 2.3 模拟器上它都有效:S 但是当我在手机上尝试第一种方法时,它运行良好..我明天得看看
    【解决方案3】:

    这是执行此操作的方法,这是使用您应用中的构建信息的通用答案。您必须使用 FLAG_ACTIVITY_NEW_TASK 并为您的应用构建正确的 URI

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

    例如,您可以在小吃店使用它。

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

    【讨论】:

      【解决方案4】:

      为您的应用启动应用信息设置。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多