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

Solution 1:

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"));
    }
}

Solution 2:

I can suggest to create the initial (temporary) file at first, then pass the Uri in the Intent. In the function "onActivityResult()" you will have the file with the filled image.

File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "folderName");
dir.mkdirs();

if (dir.exists()) {
    try {
        imageFile = File.createTempFile("IMG_", ".jpg", dir);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

if (imageFile != null) {
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
    activity.startActivityForResult(cameraIntent, REQUEST_CODE);
}