android7.0及以上TelephonyManager.ge

2018-04-26  本文已影响0人  majorty

在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;
    }
上一篇 下一篇

猜你喜欢

热点阅读