Android设备有唯一的ID吗?如果有,使用Java访问它的简单方法是什么?


当前回答

谷歌现在有一个广告ID。这也可以使用,但请注意:

广告ID是用户特定的、唯一的、可重置的ID

and

使用户可以在Google Play应用程序中重置其标识符或选择退出基于兴趣的广告。

因此,尽管这个id可能会改变,但似乎很快我们就没有选择了,这取决于这个id的用途。

更多信息@develper.android

在此处复制粘贴代码

HTH

其他回答

TelephonyManager.getDeviceId()返回唯一的设备ID,例如,GSM的IMEI和CDMA电话的MEID或ESN。

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

但我建议使用:

Settings.Secure.ANDROID_ID,将ANDROID ID作为唯一的64位十六进制字符串返回。

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

有时TelephonyManager.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;
}

我要补充一点,我有一种独特的情况。

使用:

deviceId = Secure.getString(this.getContext().getContentResolver(), Secure.ANDROID_ID);

事实证明,即使我的优派G平板电脑报告的DeviceID不为空,但每个G平板电脑都报告相同的数字。

玩“Pocket Empires”很有趣,它可以让您基于“唯一”DeviceID即时访问某人的帐户。

我的设备没有手机收音机。

这个示例演示了如何在Android中获取和存储设备ID,但我使用的是Kotlin。

      val textView: TextView = findViewById(R.id.textView)
      val uniqueId: String = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
      textView.text = "Device ID: $uniqueId"
android.telephony.TelephonyManager.getDeviceId()

这将返回唯一标识设备的任何字符串(GSM上的IMEI,CDMA上的MEID)。

在AndroidManifest.xml中需要以下权限:

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

检查系统信息设备唯一标识符

文档:http://docs.unity3d.com/Documentation/ScriptReference/SystemInfo-deviceUniqueIdentifier.html

唯一的设备标识符。它保证对每个设备都是唯一的(只读)。

iOS:在iOS7之前的设备上,它将返回MAC地址的哈希。在iOS7设备上,它将是UIDevice identifierForVendor,如果由于任何原因失败,则是ASIdentifierManager advertisingIdentifier。