简体   繁体   English

如何获得 package 名称?

[英]How to get package names?

How can i display all the package names of all apps installed in my phone.如何显示我手机中安装的所有应用程序的所有 package 名称。 Also adding button to open direct setting of that app.还添加按钮以打开该应用程序的直接设置。

I want to check if a perticular app package is available on phone or not.我想检查手机上是否有特定的应用程序 package 可用。

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
                    } catch (android.content.ActivityNotFoundException anfe) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));

try this:尝试这个:

final PackageManager packageManager = getPackageManager();

List<ApplicationInfo> packages =   packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
  Log.d(TAG, "Installed package :" + packageInfo.packageName);
  Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
  Log.d(TAG, "Launch Activity :" + packageManager.getLaunchIntentForPackage(packageInfo.packageName)); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM