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

后端 未结 9 2234

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 17:54

    With the advent of the new Intel native emulator the above mentioned methods did not work any longer. Now I am using this code snippet which works on both Intel and ARM emulators:

    if (Build.MODEL.contains("google_sdk") ||
        Build.MODEL.contains("Emulator") ||
        Build.MODEL.contains("Android SDK")) {
      RunsInEmulator = true;
    }
    

提交回复
热议问题