6.0权限 乐视手机打不开权限

 if (ContextCompat.checkSelfPermission(this,
                android.Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.READ_PHONE_STATE)) {
                // 用户拒绝过这个权限了,应该提示用户,为什么需要这个权限。
//                startPermissionAppPermission(this);
            } else {
                // 申请授权。
                ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.READ_PHONE_STATE}, CODE_FOR_WRITE_PERMISSION);
//                startPermissionAppPermission(this);
            }
        } else {

//            startPermissionAppPermission(this);
            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            String imei = tm.getDeviceId();
            AccountUtil.getInstance(this).setIMEI(imei);
            LogUtils.LOGI("tag", "imei==" + imei);
        }

 @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == CODE_FOR_WRITE_PERMISSION) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
//                ToastUtils.shortToast(MainActivity.this, "=Granted==onRequestPermissionsResult==");
                if (StringUtils.isEmpty(AccountUtil.getInstance(this).getIMEI())){
                    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                    String imei = tm.getDeviceId();
                    AccountUtil.getInstance(this).setIMEI(imei);
                }
            } else {
                // Permission Denied
//                ToastUtils.shortToast(MainActivity.this, "=Denied=onRequestPermissionsResult==");
                //请求权限
//                ActivityCompat.requestPermissions(this,
//                        new String[]{android.Manifest.permission.READ_PHONE_STATE}, CODE_FOR_WRITE_PERMISSION);
//跳转设置(乐视手机跳转到系统设置页面手动打开权限                Intent intent = new Intent(
                Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.parse("package:" + getPackageName()));
                startActivity(intent);
                ToastUtils.shortToast(MainActivity.this, "请打开所需权限");
            }
        }
    }

你可能感兴趣的:(6.0权限 乐视手机打不开权限)