Используйте 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
}