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。
推荐文章
- Android Studio, logcat在应用程序关闭后清理
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null
- 按钮背景是透明的
- 在Mac OS X上哪里安装Android SDK ?
- 我如何获得图像缩放功能?
- 在Android应用程序中显示当前时间和日期
- BottomSheetDialogFragment的圆角
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- 我如何改变默认对话框按钮的文本颜色在安卓5
- 更改单选按钮的圆圈颜色
- 如何在android中复制一个文件?
- adb找不到我的设备/手机(MacOS X)
- 如何在新的材质主题中改变背面箭头的颜色?