SoFunction
Updated on 2025-03-08

Android method to judge real machines and emulators

Android method to judge real machines and emulators

Recently, there are some business needs to determine whether it is running on a real machine or running on an emulator to do different business logic operations under two different situations. I checked the Internet and found that there are really a lot of resources.

Next, let’s show you the example code:

private static String getSystemProperty(String name) throws Exception {
  Class systemPropertyClazz = ("");
  return (String) ("get", new Class[]{})
      .invoke(systemPropertyClazz, new Object[]{name});
}

public static boolean checkEmulator() {
  try {
    boolean goldfish = getSystemProperty("").contains("goldfish");
    boolean emu = getSystemProperty("").length() > 0;
    boolean sdk = getSystemProperty("").equals("sdk");
    if (emu || goldfish || sdk) {
      return true;
    }
  } catch (Exception e) {
  }
  return false;
}

Thank you for reading, I hope it can help you. Thank you for your support for this site!