How can I detect when an Android application is running in the emulator?

前端 未结 30 2693
无人及你
无人及你 2020-11-22 16:42

I would like to have my code run slightly differently when running on the emulator than when running on a device. (For example, using 10.0.2.2 instead of a

30条回答
  •  执念已碎
    2020-11-22 17:40

    The above suggested solution to check for the ANDROID_ID worked for me until I updated today to the latest SDK tools released with Android 2.2.

    Therefore I currently switched to the following solution which works so far with the disadvantage however that you need to put the PHONE_STATE read permission ()

    private void checkForDebugMode() {
        ISDEBUGMODE = false; //(Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID) == null);
    
        TelephonyManager man = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
        if(man != null){
            String devId = man.getDeviceSoftwareVersion();
            ISDEBUGMODE = (devId == null);
        }
    } 
    

提交回复
热议问题