简体   繁体   中英

How to get the PackageName in a listview of an Android App using PackageManager

The app I am developing requires that I get the package name using PackageManager.

在此处输入图片说明

I am able to get the App Icon and and App Name but how do I get the packagename in a way similar to what I have below?

    Drawable appIcon = packageManager
            .getApplicationIcon(packageInfo.applicationInfo);


    String appName = packageManager.getApplicationLabel(
            packageInfo.applicationInfo).toString();

我发现这是

    PACKAGE_NAME = packageInfo.packageName;
private ArrayList results = new ArrayList();
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PackageManager pm = this.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> list = pm.queryIntentActivities(intent,
            PackageManager.PERMISSION_GRANTED);
    for (ResolveInfo rInfo : list) {
        results.add(rInfo.activityInfo.applicationInfo.packageName);
        Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
                .loadLabel(pm).toString());
    }

This gives list of all package names installed in your device.

rInfo.activityInfo.applicationInfo.loadLabel(pm)
                .toString();

This gives u the app names.

rInfo.loadIcon(getPackageManager());

And this gives the appicon.

String package_name= getPackageManager().getPackageInfo(getPackageName(), 0).packageName;

要么

String package_name= MyContext.getPackageName();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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