2011-11-11 46 views

回答

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

謝謝。這是一個很酷的方式。 – Phoenix

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"); 
    } 
相關問題