2011-11-30 85 views

回答

4

你应该尝试使用以下行:

deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); 

这将让来自平板电脑的设备ID,你只使用代码工作在手机上(它将返回null在平板电脑上)

0

<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

然后

试试这个:

public String deviceId; 

则:

// ------------- get UNIQUE device ID 
     deviceId = String.valueOf(System.currentTimeMillis()); // -------- 
                   // backup for 
                   // tablets etc 
     try { 
      final TelephonyManager tm = (TelephonyManager) getBaseContext() 
        .getSystemService(Main.TELEPHONY_SERVICE); 
      final String tmDevice, tmSerial, tmPhone, androidId; 
      tmDevice = "" + tm.getDeviceId(); 
      tmSerial = "" + tm.getSimSerialNumber(); 
      androidId = "" 
        + android.provider.Settings.Secure.getString(
          getContentResolver(), 
          android.provider.Settings.Secure.ANDROID_ID); 
      UUID deviceUuid = new UUID(androidId.hashCode(), 
        ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); 
      deviceId = deviceUuid.toString(); 
     } catch (Exception e) { 
      Log.v("Attention", "Nu am putut sa iau deviceid-ul !?"); 
     } 
     // ------------- END get UNIQUE device ID 

从这里开始 - >Is there a unique Android device ID?

相关问题