This question already has an answer here:
While Capturing image in android app intent return null each time. Please see below the code which I am using. I have tried multiple ways to get the permission as well as intent set but still I am unable to get data.
Action For Camera
private void takePhotoFromCamera() {
if(ActivityCompat.checkSelfPermission(ObservationsView.this,
Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(getExternalCacheDir(),
String.valueOf(System.currentTimeMillis()) + ".jpg");fileUri = Uri.fromFile(file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}else {
String[] permissionRequest = {Manifest.permission.CAMERA};
requestPermissions(permissionRequest, 8675309);
checkPermission();
}
}
And Here is the Response Code
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK ) {
Uri selectedImg = null;
Bitmap bmp = null;
Bundle extras;
if (requestCode == CAMERA_REQUEST) {
selectedImg = data.getData();
extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
}
else if (requestCode == CAMERA_REQUEST) {
selectedImg = fileUri;
// Bitmap mphoto = (Bitmap) data.getExtras().get("data");
try {
bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), fileUri);
if (bmp != null) {
bmp = getBitmapFromUri(fileUri);
}
}catch (IOException e) {
e.printStackTrace();
}
Uri tempUri = getImageUri(getApplicationContext(), bmp);
Intent passPhoto = new Intent(this, Photo.class);
passPhoto.putExtra("image",tempUri);
passPhoto.putExtra("Caller", getIntent().getComponent().getClassName());
startActivity(passPhoto);
}
Try to use the following code for getting the image in all APIs -
And on your onActivityResult -
Also, you need to define the Provider in your Manifest.xml file -
And finally the provider_paths.xml will be as follows -
Let me know in case you need any clarification.