内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

AndroidQ適配之IMEI替換為Android_id的示例分析

這篇文章給大家分享的是有關(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

Android Q適配之IMEI替換為Android_id的示例分析

升級(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)

網(wǎng)站托管運(yùn)營
张家界市| 泸西县| 明光市| 中方县| 手游| 宿松县| 施秉县| 玉环县| 当涂县| 东阳市| 泾源县| 叙永县| 盖州市| 苍梧县| 常州市| 莱芜市| 新建县| 临颍县| 宿州市| 息烽县| 浦城县| 福鼎市| 沁阳市| 金堂县| 北票市| 湾仔区| 洛宁县| 汝阳县| 金沙县| 禹州市| 那坡县| 贵定县| 开封市| 南华县| 新安县| 历史| 兴隆县| 南郑县| 滨海县| 开江县| 武隆县|