//判断权限 private void getPermission() { // 申请一个(或多个)权限,并提供用于回调返回的获取码(用户定义) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int permission1 = ActivityCompat.checkSelfPermission(getApplication(), Manifest.permission.ACCESS_COARSE_LOCATION); //不等于就是未授权 if (permission1 != PackageManager.PERMISSION_GRANTED) { // requestPermissions(permission.toArray(new String[permission.size()]), SDK_PERMISSION_REQUEST); //判断是否可以弹出 if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION)) { // 提示 请求权限 ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE }, REQUEST_CODE_PERMISSION); } else { // 禁止 转到设置 showToast("请打开外部存储权限"); Intent intent = new Intent(); intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); intent.setData(Uri.fromParts("package", getPackageName(), null)); startActivity(intent); } } } } //去设置页面之后返回的结果 @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case REQUEST_CODE_PERMISSION: if (grantResults[0] != 0) { //未授权 showToast("请允许使用外部存储"); //未授权就退出 finish(); } else { showToast("已授权外部存储"); } break; default: L.d("未处理的权限请求码"); break; } }