16

Android デバイスごとに一意になるデバイス ID を取得したいと考えています。私は現在、タブレットデバイス用に開発しています。一意のデバイス ID を取得し、対応する値を保存したい...

それで、TelephonyManager.getDeviceId() を使用した場合にタブレット デバイスが値を返すかどうかを知りたいです...???または、各デバイスに固有の他の値がありますか???

4

3 に答える 3

60

TelephonyManger.getDeviceId()固有のデバイス ID (GSM の IMEI や CDMA 電話の MEID または ESN など) を返します。

final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);            
String myAndroidDeviceId = mTelephony.getDeviceId(); 

しかし、私は使用することをお勧めします:

Android ID を一意の 64 ビット 16 進文字列として返すSettings.Secure.ANDROID_ID 。

    String   myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 

TelephonyManger.getDeviceId()が null を返す場合があるため、一意の ID を保証するには、次のメソッドを使用します。

public String getUniqueID(){    
    String myAndroidDeviceId = "";
    TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephony.getDeviceId() != null){
        myAndroidDeviceId = mTelephony.getDeviceId(); 
    }else{
         myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 
    }
    return myAndroidDeviceId;
}
于 2011-11-16T00:37:07.110 に答える
9

This is not a duplicate question. As it turns out, Google's CTS require that getPhoneType of TelephonyManager needs to be none and getDeviceId of TelephonyManager needs to be null for non-phone devices.

So to get IMEI, please try to use:

String imei = SystemProperties.get("ro.gsm.imei")

Unfortunately, SystemProperties is a non-public class in the Android OS, which means it isn't publicly available to regular applications. Try looking at this post for help accessing it: Where is android.os.SystemProperties

于 2011-06-10T15:07:45.413 に答える