9
Hello friends I am 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, take a photo and record the photo in an Imageview, worked until Android 6.0, but now Android 7 stopped working, someone knows how to solve ?
Follow my code below:
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);
        }
    }
}
Grateful !!!