已安装应用程序的包名

Packagename of Installed apps

我想研究与 Package Name Viewer 2.0 that could load the packagenames of all the installed apps in the device. Actually I have searched a lot about it even discussed with my seniors and even tried to contact with the owner of Package Name Viewer 2.0 类似的 app,但没有得到答复。我不是要求编写整个代码只是帮我一个忙,我怎样才能做到这一点。

简而言之:我想在 onCreate() 中添加代码,当应用程序启动时它应该加载所有 packagenames 已安装的应用程序。

相关问题:How to get package name from anywhere?

使用所有应用程序的 PackageManager to retrieve ApplicationInfo

 public static List<App> getAllAppInstalled(Context context) {
    PackageManager packageManager = context.getPackageManager();
    List<App> apps = new ArrayList<>();
    List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

    for (ApplicationInfo packageInfo : packages) {
        String applicationName = ((packageInfo != null) ? packageManager.getApplicationLabel(packageInfo) : "Unknown").toString();
        if (packageInfo.enabled) {
            apps.add(new App(applicationName, packageInfo.packageName));
        }
    }

    return apps;
}

应用 class 应如下所示:

public class App {
private String appName;
private String appPackage;

public App(String appName, String appPackage) {
    this.appName = appName;
    this.appPackage = appPackage;
}
//getters and setters
}