android判断模拟器的三种方法

private boolean checkEmulator1(){//基于电话号码,模拟器的电话号码是几个固定值
            String[] known_numbers = {"15555215554","15555215556",
                "15555215558","15555215560","15555215562","15555215564",
                "15555215566","15555215568","15555215570","15555215572",
                "15555215574","15555215576","15555215578","15555215580",
                "15555215582","15555215584"};
                TelephonyManager    tm = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);
                String  number = tm.getLine1Number();
                for(String i:known_numbers){
                    if(i.equals(number)){
                        return true;
                    }
                }
                return false;
    }
    private boolean checkEmulator2(){//基于SubscriberId
        String subId = "310260000000000";
        TelephonyManager    tm = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);
        String yourId = tm.getSubscriberId();
        if(yourId.equals(subId)){
            return true;
        }else{
            return false;
        }
    }
    private boolean checkEmulator3(){//基于DeviceId,因为一般模拟器DeviceId为15个0
        TelephonyManager    pm = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);
        String  id = pm.getDeviceId();
        if(id.equals("000000000000000")){
            return true;
        }else{
            return false;
        }
    }

你可能感兴趣的:(Android)