// 不过滤,所有包名
public static List<String> getAllPackageNames() {
List<String> packageNames = new ArrayList<>();
List<ResolveInfo> resolveInfos = loadApps();
for (ResolveInfo resolveInfo : resolveInfos) {
String packageName = resolveInfo.activityInfo.packageName;
packageNames.add(packageName);
}
return packageNames;
}
//取第三方应用,过滤系统应用
public static List<String> getNullSystemPackageNames() {
List<String> packageNames = new ArrayList<>();
List<ResolveInfo> resolveInfos = loadApps();
for (ResolveInfo resolveInfo : resolveInfos) {
String packageName = resolveInfo.activityInfo.packageName;
try {
PackageManager pm = ServiceApplication.getContext().getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) {
//第三方应用
packageNames.add(packageName);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
return packageNames;
}
/**
* 获取指定包名应用的启动activity
* @param packageName
* @return
*/
public static String getActivityName(String packageName) {
String activityName = "";
List<ResolveInfo> resolveInfos = loadApps();
for (ResolveInfo resolveInfo : resolveInfos) {
if (packageName.equals(resolveInfo.activityInfo.packageName)) {
activityName = resolveInfo.activityInfo.name;
}
}
return activityName;
}