首页 > 移动平台 > 详细

android7.0关于TelephonyManager.getDeviceId()返回null的问题

时间:2017-10-09 13:46:34      阅读:777      评论:0      收藏:0      [点我收藏+]

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

 

public static String getDeviceId(Context context) {
    String id;
    //android.telephony.TelephonyManager
    TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephony.getDeviceId() != null) {
        id = mTelephony.getDeviceId();
    } else {
        //android.provider.Settings;
        id = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
    }
    return id;
}
相关资料地址:http://stackoverflow.com/questions/3802644/will-telephonymanger-getdeviceid-return-device-id-for-tablets-like-galaxy-tab

android7.0关于TelephonyManager.getDeviceId()返回null的问题

原文:http://www.cnblogs.com/lenkevin/p/7640691.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!