In my Android application I have to use accelerometer and other sensors. Since this sensors aren't emulated by a Virtual Device, I've to use SensorSimulator project. The problem is that SensorSimulator's APIs look different from Android's ones. So I've to use different code if I'm in a real or in a virtual device. Does it exists a way to programmatically detect it? Or do you know other solutions?
Asked
Active
Viewed 4,742 times
4
-
see http://code.google.com/p/openintents/wiki/SensorSimulator – njzk2 Nov 23 '12 at 08:25
4 Answers
7
The following is true for an emulator...
Build.FINGERPRINT.startsWith("generic")
or
boolean inEmulator = "generic".equals(Build.BRAND.toLowerCase());

Nermeen
- 15,883
- 5
- 59
- 72
7
You can try, by checking Build.DEVICE
which for not real device shall read generic
or check Build.PRODUCT
which would be sdk
.

Marcin Orlowski
- 72,056
- 11
- 123
- 141
-
-
Build.BRAND and Build.DEVICE can be "generic_x86" for x86 architecture, and Build.PRODUCT can be "sdk_google_phone_x86" – Joe Bowbeer Oct 28 '15 at 08:04
1
I know it's an old question but just had the same issue. I modified Nermeen answer a bit as it doesn't work anymore:
boolean inEmulator = Build.FINGERPRINT.contains("generic");

krlzlx
- 5,752
- 14
- 47
- 55

user3091593
- 33
- 4
1
There are so many ways to achieve this goal, such as: (1) cat /proc/cpuinfo, emulator contains "goldfish", real devices contains "Qualcomm MSM xxxx",etc. (2) features listed as follows show that it is an emulator:
private static String[] known_pipes={
"/dev/socket/qemud",
"/dev/qemu_pipe"
};
private static String[] known_qemu_drivers = {
"goldfish"
};
private static String[] known_files = {
"/system/lib/libc_malloc_debug_qemu.so",
"/sys/qemu_trace",
"/system/bin/qemu-props"
};
private static String[] known_numbers = { "15555215554", "15555215556",
"15555215558", "15555215560", "15555215562", "15555215564",
"15555215566", "15555215568", "15555215570", "15555215572",
"15555215574", "15555215576", "15555215578", "15555215580",
"15555215582", "15555215584", };
private static String[] known_device_ids = {
"000000000000000"// default ID on emulator
};
see the paper "Morpheus: Automatically Generating Heuristics to Detect Android Emulators" for more infomation.

whuwangyong
- 59
- 1
- 6