Android juge s'il s'agit d'un émulateur (en fait mesuré Ye Shen passé)

1. Composez les paramètres du téléphone et de l'appareil

 /**
     * 检测当前设备是否是模拟器.
     */
    public static boolean checkEmulator(Context context) {
        String url = "tel:" + "123456";
        Intent intent = new Intent();
        intent.setData(Uri.parse(url));
        intent.setAction(Intent.ACTION_DIAL);
        // 是否可以处理跳转到拨号的 Intent
        boolean canResolveIntent = intent.resolveActivity(context.getPackageManager()) != null;

       String fingerprint = Build.FINGERPRINT;//唯一标识此版本的字符串。
        String model = Build.MODEL;//手机型号
        String serial = Build.SERIAL;//硬件序列号,安卓8.1废弃.
        return fingerprint.startsWith("generic")
                || fingerprint.toLowerCase().contains("vbox")
                || fingerprint.toLowerCase().contains("test-keys")
                || model.contains("google_sdk")
                || model.contains("Emulator")
                || model.contains("Android SDK built for x86")
                || serial.equalsIgnoreCase("unknown")
                || serial.equalsIgnoreCase("android")
                || Build.MANUFACTURER.contains("Genymotion")//制造商
                || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
                || "google_sdk".equals(Build.PRODUCT)//整体产品的名称
                || ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
                .getNetworkOperatorName().toLowerCase().equals("android")
                || !canResolveIntent;

    }

2. Capteur de lumière

/**
 * 判断是否存在光传感器来判断是否为模拟器
 * 部分真机也不存在温度和压力传感器。其余传感器模拟器也存在。
 * @return true 为模拟器
 */
public static Boolean notHasLightSensorManager(Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE);
    Sensor sensor8 = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); //光
    if (null == sensor8) {
        return true;
    } else {
        return false;
    }
}

3.Bluetooth

  /*
     *判断蓝牙是否有效来判断是否为模拟器
     *返回: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;
            }
        }
    }

4. CPU

 /*
    *根据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;
   }

Guess you like

Origin blog.csdn.net/zhao8856234/article/details/128149231