最近有看到网上有很多都可以用模拟器刷单什么的,现在为了禁止这种事情出现,就写了一个判断如何是模拟器操作
方法使用:
if (Android_ID_Utils.notHasBlueTooth()||Android_ID_Utils.notHasLightSensorManager(this)||
Android_ID_Utils.isFeatures()||Android_ID_Utils.checkIsNotRealPhone()){
ToastUtils.ToastLong(this,"检查你设备是模拟器");
return;
}
方法实体:
/*
*用途:判断蓝牙是否有效来判断是否为模拟器
*返回:true 为模拟器
*/
public static boolean notHasBlueTooth() {
BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
if (ba == null) {
return true;
} else {
// 如果有蓝牙不一定是有效的。获取蓝牙名称,若为null 则默认为模拟器
String name = ba.getName();
if (TextUtils.isEmpty(name)) {
return true;
} else {
return false;
}
}
}
/*
*用途:依据是否存在光传感器来判断是否为模拟器
*返回:true 为模拟器
*/
public static Boolean notHasLightSensorManager(Context context) {
SensorManager sensorManager = (SensorManager) context.getSystemService(context.SENSOR_SERVICE);
Sensor sensor8 = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); //光
if (null == sensor8) {
return true;
} else {
return false;
}
}
/*
*用途:根据部分特征参数设备信息来判断是否为模拟器
*返回:true 为模拟器
*/
public static boolean isFeatures() {
return Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.toLowerCase().contains("vbox")
|| Build.FINGERPRINT.toLowerCase().contains("test-keys")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| "google_sdk".equals(Build.PRODUCT);
}
/*
*用途:根据CPU是否为电脑来判断是否为模拟器
*返回:true 为模拟器
*/
public static boolean checkIsNotRealPhone() {
String cpuInfo = readCpuInfo();
if ((cpuInfo.contains("intel") || cpuInfo.contains("amd"))) {
return true;
}
return false;
}
/*
*用途:根据CPU是否为电脑来判断是否为模拟器(子方法)
*返回:String
*/
public static String readCpuInfo() {
String result = "";
try {
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
ProcessBuilder cmd = new ProcessBuilder(args);
Process process = cmd.start();
StringBuffer sb = new StringBuffer();
String readLine = "";
BufferedReader responseReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8"));
while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine);
}
responseReader.close();
result = sb.toString().toLowerCase();
} catch (IOException ex) {
}
return result; }
感谢赵星海大哥
|
|