美文网首页
android7.0及以上TelephonyManager.ge

android7.0及以上TelephonyManager.ge

作者: majorty | 来源:发表于2018-04-26 13:48 被阅读0次

在android7.0及以上的系统下发现TelephonyManager.getDeviceId()在权限允许的情况下取得返回值也为null,解决方法如下:

    /**
     * 获取设备的id
     * @return
     */
    private String getDeviceId(){
        TelephonyManager  telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String deviceId = telephonyManager.getDeviceId();
        if (deviceId==null){
            //android.provider.Settings;
            deviceId= Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
        }
        return deviceId;
    }

相关文章

网友评论

      本文标题:android7.0及以上TelephonyManager.ge

      本文链接:https://www.haomeiwen.com/subject/glwplftx.html