這篇文章給大家分享的是有關(guān)Android Q適配之IMEI替換為Android_id的示例分析的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名申請、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、圖木舒克網(wǎng)站維護、網(wǎng)站推廣。
前置工作:
項目配置升到對應(yīng)的29版本
compileSdkVersion: 29,
buildToolsVersion: ‘29.0.0',
minSdkVersion : 19,
targetSdkVersion : 29,
javaVersion : JavaVersion.VERSION_1_8

升級到Android Q后的權(quán)限提示界面
老版本獲取IMEI的方法:
public static String getIMEI(Context context) {
String deviceId = null;
try {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
deviceId = tm.getDeviceId();
if (deviceId == null || "".equals(deviceId)) {
return getLocalMacAddress(context);
}
} catch (Exception e) {
e.printStackTrace();
if (deviceId == null || "".equals(deviceId)) {
return getLocalMacAddress(context);//獲取Mac地址,在Android 9 P版本中,地址會隨機變化,不可用作唯一標識,可去掉。
}
}
return deviceId;
}Android Q獲取IMEI方法
public static String getIMEI(Context context) {
String deviceId = null;
try {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
deviceId = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
} else {
// request old storage permission
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return null;
}
deviceId = tm.getDeviceId();
}
if (deviceId == null || "".equals(deviceId)) {
return getLocalMacAddress(context);
}
} catch (Exception e) {
e.printStackTrace();
if (deviceId == null || "".equals(deviceId)) {
return getLocalMacAddress(context);
}
}
return deviceId;
}谷歌官方有聲明:手機恢復(fù)出廠設(shè)置,Android ID會重置。
如果用戶拒絕權(quán)限,也還是會獲取不到設(shè)備標識。
感謝各位的閱讀!關(guān)于“Android Q適配之IMEI替換為Android_id的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
當前名稱:AndroidQ適配之IMEI替換為Android_id的示例分析
文章轉(zhuǎn)載:http://chinadenli.net/article24/gspgce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、微信公眾號、App開發(fā)、面包屑導(dǎo)航、網(wǎng)站設(shè)計公司、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)