应用能否在 android 模拟器中识别它们 运行?

Can apps recognize that they run in an android emulator?

我想知道 android 应用程序如何在 android 模拟器中发现它是 运行。除此之外,如果设备是刚启动的,则没有安装用户文件和其他应用程序。是否有关于该主题的任何资源?

提前致谢

可以了解您的应用 运行 所在设备的详细信息。从这些详细信息中,您可以确定该设备是模拟器还是物理设备。 请通过下面的 link 查看指纹、制造商、设备、型号、产品。

https://developer.android.com/reference/android/os/Build.html

例如: 在您的初始屏幕中,如果您输入以下代码,那么在您的 Logcat 中您应该会看到如下日志

`Log.e(TAG, "------------");
 Log.e(TAG, "Device Values");
 Log.e(TAG, "Fingerprint: " + Build.FINGERPRINT);
 Log.e(TAG, "Brand: " + Build.BRAND);
 Log.e(TAG, "Device: " + Build.DEVICE);
 Log.e(TAG, "Manufacturer: " + Build.MANUFACTURER);
 Log.e(TAG, "Model: " + Build.MODEL);
 Log.e(TAG, "Product: " + Build.PRODUCT);

 Real Device

 2020-03-15 20:46:07.136 32602-32602/com.utkarshnew.android E/NewSplashScreen:    ------------
 2020-03-15 20:46:07.136 32602-32602/com.utkarshnew.android E/NewSplashScreen:     Device Values
 2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Fingerprint: iBall/iBall_Slide_Cleo_S9/iBall_Slide_Cleo_S9:8.1.0/OPM2.1710/47218:user/release-keys
 2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Brand: iBall
 2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Device: iBall_Slide_Cleo_S9
 2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Manufacturer: iBall Slide
 2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Model: iBall Slide Cleo S9
 2020-03-15 20:46:07.137 32602-32602/com.utkarshnew.android E/NewSplashScreen: Product: iBall_Slide_Cleo_S9

 Emulator

 2020-03-15 20:53:44.725 6736-6736/com.utkarshnew.android E/NewSplashScreen: ------------
 2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Device Values
 2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Fingerprint: google/sdk_gphone_x86/generic_x86:10/QSR1.190920.001/5891938:user/release-keys
 2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Brand: google
 2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Device: generic_x86
 2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Manufacturer: Google
 2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Model: Android SDK built for x86
 2020-03-15 20:53:44.726 6736-6736/com.utkarshnew.android E/NewSplashScreen: Product: sdk_gphone_x86`

如果您看到上面的日志,您会发现对于 Emulator,Device 值将显示为 Generic,而对于物理设备,它将显示设备型号的名称。

此外,请参阅这些 links

How can I detect when an Android application is running in the emulator?