应用程序随机崩溃,显示权限拒绝异常。这是错误日志
5
答案 0 :(得分:0)
我认为你在Marshmallow设备上运行尝试处理权限运行时。
需要读取外部存储
public boolean checkPermissionREAD_EXTERNAL_STORAGE(
final Context context) {
int currentAPIVersion = Build.VERSION.SDK_INT;
if (currentAPIVersion >= android.os.Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(
(Activity) context,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
showDialog("External storage", context,
Manifest.permission.READ_EXTERNAL_STORAGE);
} else {
ActivityCompat
.requestPermissions(
(Activity) context,
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
}
return false;
} else {
return true;
}
} else {
return true;
}
}`enter code here`
答案 1 :(得分:0)
在Manifest中添加:
<user-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
如果不起作用
https://developer.android.com/training/permissions/requesting.html