如何判断Android设备是真机还是模拟器

2025-03-12 16:25:17
推荐回答(1个)
回答1:

方法很多呀,
例如横竖屏幕代码检测,调用电话功能检测、蓝牙模块检测等等,
这里有一个蓝牙模块检测的代码,你可以参考一下:
系统在启动的时候会做一次判断,看看SystemServer.java里是怎么判断的:

boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");

然后,如果是模拟器,是不会起bluetooth服务的:

if (isEmulator) {

Slog.i(TAG, "No Bluetooh Service (emulator)");

} else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {

Slog.i(TAG, "No Bluetooth Service (factory test)");

} else if (!context.getPackageManager().hasSystemFeature

(PackageManager.FEATURE_BLUETOOTH)) {

Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");

} else if (disableBluetooth) {

Slog.i(TAG, "Bluetooth Service disabled by config");

} else {

Slog.i(TAG, "Bluetooth Service");

mSystemServiceManager.startService(BluetoothService.class);

}