By means of an Intent defined as CATEGORY_LAUNCHER
, you can obtain a list of installed application packages:
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List listaPaquetesAppsInstaladas = getPackageManager().queryIntentActivities(intent, 0)
To add the data in a ListView
, this is a complete example:
//Crea List para almacenar packagename de las aplicaciones.
List<String> listaPaquetesAppsInstaladas = new ArrayList<>();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//Obtiene datos de apps instaladas
List<ResolveInfo> listAppsInstaladas = getPackageManager().queryIntentActivities(intent, 0);
for(ResolveInfo info : listAppsInstaladas) {
// be added
ApplicationInfo applicationInfo;
if (info == null || (applicationInfo = info.activityInfo.applicationInfo) == null
|| !applicationInfo.enabled || listaPaquetesAppsInstaladas.contains(applicationInfo.packageName)) {
continue;
}
listaPaquetesAppsInstaladas.add(applicationInfo.packageName);
}
//Instancía adapter con datos obtenidos
final ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, listaPaquetesAppsInstaladas);
//Muestra datos en ListView
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
To obtain the application packages in ListView
.