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

前端 未结 30 2845
无人及你
无人及你 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:32

    My recommendation:

    try this from github.

    Easy to detect android emulator

    • Checked on real devices in Device Farm (https://aws.amazon.com/device-farm/)
    • BlueStacks
    • Genymotion
    • Android Emulator
    • Andy 46.2.207.0
    • MEmu play
    • Nox App Player
    • Koplayer
    • .....

    How to use with an Example:

    EmulatorDetector.with(this)
                    .setCheckTelephony(true)
                    .addPackageName("com.bluestacks")
                    .setDebug(true)
                    .detect(new EmulatorDetector.OnEmulatorDetectorListener() {
                        @Override
                        public void onResult(boolean isEmulator) {
                            if(isEmulator){
                             // Do your work
                            }
                            else{
                            // Not emulator and do your work
                            }
                        }
                    });
    

提交回复
热议问题