I want to get number of total apps in android and make sure that this is not working.
int numberOfInstalledApps = getPackageManager().getInstalledApplications(0).size();
This always returns 138, If I uninstall a app then returns 138 If I download an app then returns 138.
To get the non-system applications installed on the device, you can do the following:
public static ArrayList<String> getAllInstalledApps() {
ArrayList<String> applicationsList = new ArrayList<>();
List<PackageInfo> packageList = getPackageManager()
.getInstalledPackages(0);
for (int i=0; i < packageList.size(); i++) {
PackageInfo packInfo = packageList.get(i);
if ((packInfo.applicationInfo.flags
& ApplicationInfo.FLAG_SYSTEM) == 0) {
String applicationName = packInfo.applicationInfo
.loadLabel(getPackageManager()).toString();
applicationsList.add(applicationName);
Log.e("App >" + Integer.toString(i), applicationName);
}
}
return applicationsList;
}
You can then get the list by doing:
int number = getInstalledApps().size();
You can also start any of the applications by calling:
Intent callAppIntent = new Intent(Intent.ACTION_MAIN, null);
callAppIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List appsList = context.getPackageManager()
.queryIntentActivities(callAppIntent, 0);
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.