My question is how to make sure the app is running from a mobile device and not over a emulator? Unity Preprocessor can tell the difference?
My code is something like this:
#if UNITY_IPHONE
Debug.Log("Running on Apple Device.");
#elif UNITY_ANDROID
Debug.Log("Running on Android Device.");
#elif UNITY_WP8
Debug.Log("Running on WP Device.");
#else
Debug.Log("Not running on mobile Device.");
#endif
The preprocessors are determined at build time. So if you are building an Android APK then UNITY_ANDROID is true. Thus there should be no difference between Android device and the Android emulator.
I’m not sure how to tell if the app is running on emulator. But preprocessors will not be the way to do it.
It’s not possible. The whole point of an emulator is to run the app in a virtual environment on a different operating system and have it not know about this.
I’ll Look into that, but couldn’t one change the device name on the emulator to mimic a real device?
I’m just trying to not run the app if it is running on an emulator.
Thanks!
This will also execute in the Editor if Android is set as your target platform. To avoid things running in the editor you would do:
#if UNITY_ANDROID && !UNITY_EDITOR
//code here
#endif
As for emulator detection… not sure how much you’ll be able to do and how much requires actual access to the SDK, but here’s something to get you started: