我一直在寻找Google,并且在堆栈溢出时寻找该问题的答案。为什么我无法在Android清单文件中的DCIM目录中创建具有正确权限的文件夹...这是代码,希望有人可以帮助我。
bootstrap
在stackoverflow上找到了此代码。...
答案 0 :(得分:0)
在android 6.0之后,您需要动态检查或请求权限。使用以下代码检查是否需要权限
private boolean needPermission() {
return ContextCompat.checkSelfPermission(
ApplicationUtils.getAppContext(), WRITE_EXTERNAL_STORAGE_PERM) !=
PackageManager.PERMISSION_GRANTED;
}
并使用以下代码请求权限
public void requestPermission() {
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
showDialog(R.string.title_permission, R.string.rational_permission_writing_external_storage,
android.R.string.ok, android.R.string.cancel, false,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("TAG", "should try to request the permission");
requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE_PERM},
REQUEST_WRITE_EXTERNAL_STORAGE);
}
}, null);
} else {
Log.i("TAG", "should try to request the permission");
requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE_PERM},
REQUEST_WRITE_EXTERNAL_STORAGE);
}
}