我的要求是調用一個函數的特定變體,如果它是模擬器,並且它是一個不同的硬件變體。是否有一些實用功能來識別代碼是否在仿真器或硬件上運行?
1
A
回答
0
我用這個代碼(和你的代碼來拉得序列號)
public static String getDeviceSerialNumber(Context ctx)
{
String phoneSerial = null;
try
{
phoneSerial = ((TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
}
catch(Exception ex)
{
phoneSerial = null;
}
//If it's not a phone or for some reason we can't get serial/IMEI - get serial from
if (phoneSerial == null)
{
try
{
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
phoneSerial = (String) get.invoke(c, "ro.serialno");
} catch (Exception ignored) {}
}
return phoneSerial;
}
public static boolean isRunningInEmulator(Context ctx)
{
return "000000000000000".equals(getDeviceSerialNumber(ctx));
}
0
使用Build.DEVICE。
0
我用
String bpStr = Build.PRODUCT;
if ("google_sdk".equals(bpStr))
// IT'S RUNNING ON THE EMULATOR
0
雖然其他選擇似乎在我看來更好,因爲你永遠不知道,如果未來的設備將忽略包括這個,你也可以檢查一個加速度傳感器。仿真器不支持其中之一,並且目前所有具有android market和google native應用程序的手機都有一個加速度計。
在onCreate中,實現SensorEventListener後;
SensorManager manager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() == 0) {
textView.setText("No accelerometer installed");
}
相關問題
- 1. 是否可以在GA144上運行仿真的C代碼?
- 2. 是否有可能判斷它是否在模擬器或應用程序中的真實設備上運行
- 3. 是否有身份識別功能?
- 4. 是否有scala身份識別功能?
- 5. API調用以檢查是否在仿真器中運行wp7
- 6. 地理編碼器是否在仿真器上工作
- 7. 是否可以像仿真器一樣顯示真實設備?
- 8. 如何識別代碼是否在web服務中運行?
- 9. 是否有一種方法來檢測代碼是否被本地,測試環境或在App Engine上運行?
- 10. 是否在GPU上運行opengl代碼?
- 11. 如何識別我的容器是否在AWS ECS上運行?
- 12. 功能是否真的使代碼有效?
- 13. iPhone的識別碼是否有唯一的代碼?
- 14. 是否有可能在GPU中運行一塊純C++代碼
- 15. 是否可能在硬件
- 16. 使用#if來確定代碼是否在WP8上運行
- 17. 如何識別功能是否被執行或沒有在PostgreSQL中
- 18. 是否可以在Amazon EC2實例中運行Windows Phone 7.1仿真器?
- 19. 如何在真實手機而不是仿真器上運行應用程序。
- 20. Android應用程序未在仿真器上運行也不是真實設備
- 21. 是否有任何仿真器編程教程或指南?
- 22. 是否有一些源代碼縮寫?
- 23. 如何確定apk是否在模擬器或真實設備上運行?
- 24. networkx是否有一些XML或JSON編碼器/解碼器?
- 25. Android(在ARM上)是否具有硬件性能計數器?
- 26. 在仿真器上仿真運動API
- 27. 硬件仿真
- 28. 硬件仿真
- 29. 確保Python代碼是否在GPU或CPU上運行
- 30. 是否有可能在仿真器上顯示windows phone 7設備信息
謝謝。這是一個很酷的方式。 – Phoenix