How to find out from code if my Android app runs on emulator or real device?

后端 未结 9 2253

I have read this stackoverflow thread already and I tried using the code given in that answer to find out if I run my code on the emulator or on a real device:



        
9条回答
  •  悲&欢浪女
    2020-12-09 18:03

    This should do it:

    boolean inEmulator = false;
    String brand = Build.BRAND;
    if (brand.compareTo("generic") == 0)
    {
        inEmulator = true;
    }
    

    EDIT:

    boolean inEmulator = "generic".equals(Build.BRAND.toLowerCase());
    

提交回复
热议问题