答案 0 :(得分:0)
您是否已授予使用相机所需的权限,还需要运行时权限以及清单权限。
public boolean CheckPermissionForWriteStorage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSIONS_REQUEST_CODE_WRITE_EXTERNAL_STORAGE);
return false;
}
return true;
}
使用上面的代码获取权限 以及onACtivityResult中的代码
final boolean isCamera;
if (data == null) {
isCamera = true;
} else {
final String action = data.getAction();
if (action == null) {
isCamera = false;
} else {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
isCamera = true;
} else {
isCamera = action.equalsIgnoreCase(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
}
}
}
if (isCamera) {
String selectedImagePath = getImagePath();
aQuery.id(imgFarmerPhoto).image(selectedImagePath);
} else {
String selectedImagePath = getAbsolutePath(data.getData());
selectedImagePath = getRightAngleImage(selectedImagePath);
aQuery.id(imgFarmerPhoto).image(selectedImagePath);
}