一个识别工具类,android12-14测试有效,其他版本未测:
public class EmulatorDetectionUtil {
private static final String[] PKG_NAMES = {"com.mumu.launcher", "com.ami.duosupdater.ui", "com.ami.launchmetro", "com.ami.syncduosservices", "com.bluestacks.home",
"com.bluestacks.windowsfilemanager", "com.bluestacks.settings", "com.bluestacks.bluestackslocationprovider", "com.bluestacks.appsettings", "com.bluestacks.bstfolder",
"com.bluestacks.BstCommandProcessor", "com.bluestacks.s2p", "com.bluestacks.setup", "com.bluestacks.appmart", "com.kaopu001.tiantianserver", "com.kpzs.helpercenter",
"com.kaopu001.tiantianime", "com.android.development_settings", "com.android.development", "com.android.customlocale2", "com.genymotion.superuser",
"com.genymotion.clipboardproxy", "com.uc.xxzs.keyboard", "com.uc.xxzs", "com.blue.huang17.agent", "com.blue.huang17.launcher", "com.blue.huang17.ime",
"com.microvirt.guide", "com.microvirt.market", "com.microvirt.memuime", "cn.itools.vm.launcher", "cn.itools.vm.proxy", "cn.itools.vm.softkeyboard",
"cn.itools.avdmarket", "com.syd.IME", "com.bignox.app.store.hd", "com.bignox.launcher", "com.bignox.app.phone", "com.bignox.app.noxservice", "com.android.noxpush",
"com.haimawan.push", "me.haima.helpcenter", "com.windroy.launcher", "com.windroy.superuser", "com.windroy.launcher", "com.windroy.ime", "com.android.flysilkworm",
"com.android.emu.inputservice", "com.tiantian.ime", "com.microvirt.launcher", "me.le8.androidassist", "com.vphone.helper", "com.vphone.launcher", "com.duoyi.giftcenter.giftcenter"};
private static final String[] PATHS = {"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "/system/lib/libc_malloc_debug_qemu.so", "/sys/qemu_trace", "/system/bin/qemu-props",
"/dev/socket/qemud", "/dev/qemu_pipe", "/dev/socket/baseband_genyd", "/dev/socket/genyd"};
private static final String[] FILES = {"/data/data/com.android.flysilkworm", "/data/data/com.bluestacks.filemanager"};
// 包名检测
public static boolean isSimulator3(Context paramContext) {
try {
List pathList = new ArrayList();
pathList = getInstalledSimulatorPackages(paramContext);
if (pathList.size() == 0) {
for (int i = 0; i < PATHS.length; i++)
if (i == 0) {
if (new File(PATHS[i]).exists()) continue;
pathList.add(Integer.valueOf(i));
} else {
if (!new File(PATHS[i]).exists()) continue;
pathList.add(Integer.valueOf(i));
}
}
if (pathList.size() == 0) {
pathList = loadApps(paramContext);
}
return (pathList.size() == 0 ? null : pathList.toString()) != null;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private static List getInstalledSimulatorPackages(Context context) {
ArrayList localArrayList = new ArrayList();
try {
for (int i = 0; i < PKG_NAMES.length; i++)
try {
context.getPackageManager().getPackageInfo(PKG_NAMES[i], PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
localArrayList.add(PKG_NAMES[i]);
} catch (PackageManager.NameNotFoundException localNameNotFoundException) {
}
if (localArrayList.size() == 0) {
for (int i = 0; i < FILES.length; i++) {
if (new File(FILES[i]).exists()) // 检测的特定文件
localArrayList.add(FILES[i]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return localArrayList;
}
public static List loadApps(Context context) {
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<String> list = new ArrayList<>();
List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(intent, 0);
//for循环遍历ResolveInfo对象获取包名和类名
for (int i = 0; i < apps.size(); i++) {
ResolveInfo info = apps.get(i);
String packageName = info.activityInfo.packageName;
CharSequence cls = info.activityInfo.name;
CharSequence name = info.activityInfo.loadLabel(context.getPackageManager());
if (!TextUtils.isEmpty(packageName)) {
if (packageName.contains("bluestacks")) {
list.add("蓝叠");
return list;
}
}
}
return list;
}
}
在自带的模拟器上一般的设置都能,识别,三方的模拟器很难识别,此工具可以满足三方模拟器的识别成功率,可能也不是百分百管用。
标签:launcher,pathList,new,android,识别,com,bluestacks,模拟器 From: https://blog.51cto.com/u_14397532/12088525