[android-002]android app获取手机的imei

1.在AndroidManifest.xml文件添加权限

2.在获取imei的函数里,先获取权限,再读取参数

//如果要获取imei,必须在这里配置权限
        if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, 1);
        }


        TelephonyManager telephonyManager = (TelephonyManager)activity.getApplicationContext().getSystemService( Context.TELEPHONY_SERVICE );
        String imeistring = telephonyManager.getDeviceId();

 

你可能感兴趣的:([android-002]android app获取手机的imei)