Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import java.util.List; import android.content.pm.ApplicationInfo; import java.util.ArrayList; import java.util.Collections; public class Main { /** * Get package names of all installed apps. * @param with_system Mark if system apps are included or not. */ public static String[] getAllInstalledPackageNames(Context context, boolean with_system) { List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(0); if (packages == null) { return null; } List<String> result = new ArrayList<>(); for (ApplicationInfo applicationInfo : packages) { //Skip over system apps. if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1 && !with_system) { continue; } result.add(applicationInfo.packageName); } Collections.sort(result); return result.toArray(new String[result.size()]); } }