美文网首页
2018-03-20 动态申请权限

2018-03-20 动态申请权限

作者: 鼓励自己前进 | 来源:发表于2018-03-20 16:17 被阅读0次

private void initPermission() {

//手机唯一识别码,android:IMEI

    TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_PHONE_STATE},1);

}

Sessions.getInstance().setPhoneSn(telephonyManager.getDeviceId());

LogUtil.i(TAG,"IMEI = " + telephonyManager.getDeviceId());

//申请地址权限

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED

            || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED

            || ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,

Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_PHONE_STATE},100);

}

//申请蓝牙

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED

            || ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED

            || ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_PRIVILEGED) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.BLUETOOTH,

Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH_PRIVILEGED},100);

}

}

相关文章

网友评论

      本文标题:2018-03-20 动态申请权限

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