My Android Camera Uri Is Returning a Null Value, But the Samsung Fix Is in Place, Help

My Android camera Uri is returning a null value, but the Samsung fix is in place, help?

Your activity gets destroyed during the Camera activity operation and re-created afterwards. You should use onSaveInstanceState/onRestoreInstanceState mechanism in your activity to preserve the image URI (and any other data) upon the activity restarts.

Like this:

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mImageUri != null) {
outState.putString("cameraImageUri", mImageUri.toString());
}
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState.containsKey("cameraImageUri")) {
mImageUri = Uri.parse(savedInstanceState.getString("cameraImageUri"));
}
}

Uri returned in camera intent is null

on StackOverflow you would find these topics according to yours:

My Android camera Uri is returning a null value, but the Samsung fix is in place, help?

Camera activity returning null android

Android Camera : data intent returns null

Camera activity returning null android

You are getting wrong because you are doing it wrong way.

If you pass the extra parameter MediaStore.EXTRA_OUTPUT with the camera intent then camera activity will write the captured image to that path and it will not return the bitmap in the onActivityResult method.

If you will check the path which you are passing then you will know that actually camera had write the captured file in that path.

For further information you can follow this, this and this

Camera activity causing uri to go to null when screen orientation changes

I believe imageUri is a field in your activity, right? if you rotate the device the activity is destroyed and restarted, and your field is null. You have to save the URI as part of the state of your activity. There are a few possible methods to achieve that, on is to use onSaveInstanceState(), see here for more details: http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState%28android.os.Bundle%29

Camera Intent returns null onActivityResult

Your preinsert a uri here:

 imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

So when you get a Activity.RESULT_OK just load the taken photo by its known url. Then you can set the path onActivityResult like below but you need to convert in to Bitmap.

if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
// Convert here your uri to bitmap then set it.//
mImageView.setImageBitmap(YOUR_BITMAP);
}

Camera intent.getData() return null in some devices,Mainly in android 7.0

Camera intent.getData() return null,In some devices.

It is supposed to return null for all camera apps.

I tried following code get path of Uri of image

That code does not "get path of Uri of image". It saves the Bitmap to a random, undocumented file, then returns a Uri from the MediaStore representing that content.

It also wastes heap space, as you create a ByteArrayOutputStream, write a JPEG into it, and then throw that all away.

image quality will become poor

The image quality was poor to begin with, as you asked the camera app to give you a thumbnail image. Use EXTRA_OUTPUT to tell the camera app where to save a full-resolution image, then use that location in onActivityResult(). This sample app demonstrates this.

data is null on activity result from camera in some device

this source worked successfully
https://github.com/dustookk/AndroidImagePicker



Related Topics



Leave a reply



Submit