After I've read the Tutorial Taking Photos Simply, I tried to do it like in the tutorial.
The Problem is that on my OnePlus X it works. If I'm using other Phones like Samsung Galaxy S5 or S6 or any other device it doesn't work.
pictureActionIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (pictureActionIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
e.printStackTrace();
}
if (photoFile != null) {
//pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
}
}
startActivityForResult(pictureActionIntent, CAMERA_REQUEST);
If I delete the comment, the data
in onActivityResult
is null
.
If I set the comment, the data
looks (on Samsung device) like:
data = {android.content.Intent@19974} "Intent{act=inline-data dat=content://Media/external/images/media/16123 (has extras)}"
So, where is the problem? What do I have to change to make it working on every device?
Thank you for any help!
Kind Regards!
You need to pass the IMAGE URL also.
intent.putExtra( MediaStore.EXTRA_OUTPUT, _fileUri);
Then you can use this file path.
EDIT
private void saveFullImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == TAKE_PICTURE) && (resultCode == Activity.RESULT_OK)) {
// Check if the result includes a thumbnail Bitmap
if (data == null) {
// TODO Do something with the full image stored
// in outputFileUri. Perhaps copying it to the app folder
}
}
}