[英]Cannot get device id after upgrade android os from version 9 to 10
I have problem on getting unique device id: Settings.Secure.getString(this.contentResolver, Settings.Secure.ANDROID_ID)我在获取唯一设备 ID 时遇到问题:Settings.Secure.getString(this.contentResolver, Settings.Secure.ANDROID_ID)
You need Manifest.permission.READ_PHONE_STATE
你需要
Manifest.permission.READ_PHONE_STATE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ActivityCompat.requestPermissions(getApplicationContext(), new String[]
{Manifest.permission.READ_PHONE_STATE}, RequestCode);
}
else
{
// doesn't need permission
}
AndroidManifest.xml AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
You can use this code to get device ID:您可以使用此代码获取设备 ID:
private String deviceID;
deviceID=Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.