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 public URL to run against a development server automatically.) What is the best way to detect when an Android application is running in the emulator?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
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 (
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
)Since the underlying emulation engine for Genymotion is VirtualBox and that's not going to change any time soon I found the following code the most reliable:
I found the new emulator
Build.HARDWARE = "ranchu"
.Reference:https://groups.google.com/forum/#!topic/android-emulator-dev/dltBnUW_HzU
And also I found the Android official way to check whether emulator or not.I think it's good reference for us.
We have
ScreenShapeHelper.IS_EMULATOR
to check whether emulator.We have
Build.IS_EMULATOR
to check whether emulator.The way the official to check whether emulator is not new,and also maybe not enough,the answers above also mentioned.
But this maybe show us that the official will provide the way of official to check whether emulator or not.
As using the above all ways mentioned,right now we can also use the two ways about to check whether emulator.
How to access the
com.android.internal
package and@hide
and wait for the official open SDK.
From Battery, the emulator: Power source is always AC Charger. Temperature is always 0.
And you can use
Build.HOST
to record host value, different emulator has different host value.This code works for me
In case that device does not have sim card, It retuns empty string:""
Since Android emulator always retuns "Android" as network operator, I use above code.