已安装应用程序的软件包名称

时间:2020-05-04 16:16:40

标签: android package-name

我想研究类似于Package Name Viewer 2.0cust_id, month, recurrent_value 100 , 'FEB', 0 100 , 'MAR', 0 200 , 'JAN', 0 ,它可以加载app中所有已安装应用的packagenames。实际上,我什至搜索了很多有关此事的信息,甚至与我的前辈讨论过,甚至试图与Package Name Viewer 2.0的所有者联系,但没有得到答案。我不是要编写整个代码,而是帮我实现这一目标。

简而言之:我想在device中添加代码,以便每当应用启动时,它都应加载所有已安装的onCreate()应用。

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

1 个答案:

答案 0 :(得分:1)

使用PackageManager检索所有应用中的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;
}

应用程序类应类似于:

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

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