這篇文章給大家分享的是有關(guān)Android Q適配之IMEI替換為Android_id的示例分析的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名申請(qǐng)、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、圖木舒克網(wǎng)站維護(hù)、網(wǎng)站推廣。
前置工作:
項(xiàng)目配置升到對(duì)應(yīng)的29版本
compileSdkVersion: 29,
buildToolsVersion: ‘29.0.0',
minSdkVersion : 19,
targetSdkVersion : 29,
javaVersion : JavaVersion.VERSION_1_8
升級(jí)到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版本中,地址會(huì)隨機(jī)變化,不可用作唯一標(biāo)識(shí),可去掉。 } } 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; }
谷歌官方有聲明:手機(jī)恢復(fù)出廠設(shè)置,Android ID會(huì)重置。
如果用戶拒絕權(quán)限,也還是會(huì)獲取不到設(shè)備標(biāo)識(shí)。
感謝各位的閱讀!關(guān)于“Android Q適配之IMEI替換為Android_id的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
當(dāng)前名稱:AndroidQ適配之IMEI替換為Android_id的示例分析
文章轉(zhuǎn)載:http://www.rwnh.cn/article24/gspgce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、微信公眾號(hào)、App開發(fā)、面包屑導(dǎo)航、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)