3

Is there any way to know the game is running in an emulator application or a real device ?

Some Applications like VirtualXposed are virtual emulator for android devices. Such Applications allow users to install a game / application multiple times on their device with different identifies.

I want to know is there any way to recognize my game / application is running in emulator or a physical device in unity3d ?

something like :

if(isemulator)
   {
       dosomething();
   }
Programmer
  • 121,791
  • 22
  • 236
  • 328
iman_sh
  • 420
  • 1
  • 8
  • 22
  • Not sure, it looks like some other people also have the same question (but no answers) on the unity answer hub. I found this on how to detect if an .apk is running on an emulator: https://stackoverflow.com/questions/2799097/how-can-i-detect-when-an-android-application-is-running-in-the-emulator – Katianie Aug 16 '18 at 15:48
  • I want a simple solution @Katianie – iman_sh Aug 16 '18 at 15:56
  • 2
    A "simple" solution likely does not exist. Mainly because an application should not know or care if its on an emulator. – Draco18s no longer trusts SE Aug 16 '18 at 17:17
  • @iman_sh (please be polite) That was the most simple solution I could find. What your asking is not typical. Why do you need to know its an emulator? – Katianie Aug 16 '18 at 17:25

2 Answers2

8

It's not easy to do since there are many emulators out there. The answer from this post says that you can use Build.FINGERPRINT.contains("generic") to do that.

You can port the Java code to C# in Unity with the AndroidJavaClass class and without building Java plugin. Below is the ported version in C#:

public bool IsEmulator()
{
    AndroidJavaClass osBuild;
    osBuild = new AndroidJavaClass("android.os.Build");
    string fingerPrint = osBuild.GetStatic<string>("FINGERPRINT");
    return fingerPrint.Contains("generic");
}

To make sure that this covers most emulator, use the android-emulator-detector plugin. This plugin seems to be rigorously tested and detects most emulators. You can use AndroidJavaClass to communicate with it and UnityPlayer.UnitySendMessage to make callback into your Unity code in C#.

Programmer
  • 121,791
  • 22
  • 236
  • 328
0

Maybe you can look for some emulator specific SystemInfos (Unity Docs SystemInfo) eg. SystemInfo.deviceModel