Hello friends I'm facing the following error:
android.os.FileUriExposedException: file: ///storage/emulated/0/Pictures/1488344088086.jpg exposed beyond app through ClipData.Item.getUri ().
The intention is to open the camera, hit a photo and record the photo in an ImageView, worked until Android 6.0, but now in Android 7 has stopped working, does anyone know how to solve?
Below is my code:
private DialogInterface.OnClickListener onOriginSelect() {
return new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
if (PermissionUtils.checkPermission(PeopleActivity.this, CAMERA_REQUEST_CODE, permissoes)) {
File diretorio = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String nomeImagem = diretorio.getPath() + "/" + System.currentTimeMillis() + ".jpg";
file = new File(nomeImagem);
intentGlobal = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intentGlobal.putExtra(MediaStore.EXTRA_OUTPUT, uri.fromFile(file));
startActivityForResult(intentGlobal, CAMERA_REQUEST_CODE);
} else {
Toast.makeText(PeopleActivity.this, "ERRO CAM PERM", Toast.LENGTH_SHORT).show();
}
break;
case 1:
if (PermissionUtils.checkPermission(PeopleActivity.this, GALERIA_REQUEST_CODE, permissoes)) {
intentGlobal = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intentGlobal, CAMERA_REQUEST_CODE);
} else {
Toast.makeText(PeopleActivity.this, "PERM GALERIA", Toast.LENGTH_SHORT).show();
}
break;
}
}
};
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case GALERIA_REQUEST_CODE:
Uri uri = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
if (cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String path = cursor.getString(columnIndex);
cursor.close();
file = new File(path);
break;
}
Glide.with(getBaseContext()).load(file.getPath()).asBitmap().centerCrop().into(imagePeople);
}
}
}
Thank you!