获取手机IMEI号

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_40391500/article/details/86620761
权限
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
代码
/**
     * 获取IMEI
     * @return
     */
    public static String getIMEI() {
        String IMEI = (String) SPUtils.get(MyApplication.context, SPUtils.IMEI, "");
        if (StringUtils.isEmpty(IMEI)){
            TelephonyManager tm = (TelephonyManager) MyApplication.context.getSystemService(Context.TELEPHONY_SERVICE);
            @SuppressLint("MissingPermission")
            String deviceId = tm.getDeviceId();
            LogUtils.log(deviceId);
            if (!StringUtils.isEmpty(deviceId)){
                SPUtils.set(MyApplication.context, SPUtils.IMEI, deviceId);
            }
        }
        return IMEI;
    }

猜你喜欢

转载自blog.csdn.net/weixin_40391500/article/details/86620761
0条评论
添加一条新回复