4

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?

user1781028
  • 1,478
  • 4
  • 22
  • 45

4 Answers4

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
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
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