1

Using intent to take a photo, which is later uploaded to a server. Image is first saved to sdcard like so:

/**
 * Creating file uri to store image/video
 */
public Uri getOutputMediaFileUri(int type) {
    return Uri.fromFile(getOutputMediaFile(type));
}

/**
 * returning image / video
 */
private static File getOutputMediaFile(int type) {

    // External sdcard location
    File mediaStorageDir = new File(
            Environment
                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            Config.IMAGE_DIRECTORY_NAME);

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d(TAG, "Oops! Failed create "
                    + Config.IMAGE_DIRECTORY_NAME + " directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
            Locale.getDefault()).format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp + ".jpg");
    } else if (type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "VID_" + timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}

The saved image has no exif data. Is it due to the uri? (photos taken with the default camera app has exif data so it has to be an issue in my app).

Edit: Code used to launch default camera app:

/**
 * Launching camera app to capture image
 */
private void captureImage() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    // start the image capture Intent
    startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}

url stored:

/**
 * Here we store the file url as it will be null after returning from camera
 * app
 */
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // save file url in bundle as it will be null on screen orientation
    // changes
    outState.putParcelable("file_uri", fileUri);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    // get the file url
    fileUri = savedInstanceState.getParcelable("file_uri");
}

Source: http://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
Spagett
  • 147
  • 4
  • 16
  • 1
    "The saved image has no exif data" -- how have you determined this? – CommonsWare Jul 08 '17 at 23:29
  • I copy the img to my Windows PC then look under "Details". Doing the same thing with a picture taken with the default app shows exif data. Edit: Uploading the img to the server, then downloading it to desktop and looking under "Details" also shows no exif data. – Spagett Jul 09 '17 at 09:14
  • 1
    Could you update your question to show how you are taking the picture? – CommonsWare Jul 09 '17 at 10:46
  • Added. Also included how file uri is stored. – Spagett Jul 09 '17 at 11:59
  • Which device was that? Note *[Images taken with ACTION_IMAGE_CAPTURE always returns 1 for ExifInterface.TAG_ORIENTATION on some Gingerbread devices.](https://stackoverflow.com/questions/8450539/images-taken-with-action-image-capture-always-returns-1-for-exifinterface-tag-or)* – Alex Cohn Oct 13 '18 at 12:58

1 Answers1

2

photos taken with the default camera app has exif data so it has to be an issue in my app

Not necessarily. From the code that you have shown, it would appear to be a bug in that particular camera app. Not all camera app developers test ACTION_IMAGE_CAPTURE very well. Unless you are modifying the image sometime after the picture is taken but before you run your EXIF test, the camera app is not adding EXIF tags to pictures taken via ACTION_IMAGE_CAPTURE. These things happen.

You might install some camera apps and see how they behave with ACTION_IMAGE_CAPTURE. Open Camera, for example, supports ACTION_IMAGE_CAPTURE, though I have not tested its EXIF behavior when started with ACTION_IMAGE_CAPTURE.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491