Android EXIF data always 0, how to change it?
<p>I have an app that captures photos using the native <code>Camera</code> and then uploads them to a server. My problem is that all the photos have an EXIF orientation value of 0, and this messes up the display elsewhere.</p>

<p>How can I change the EXIF orientation? I'm not looking for a way to correct it for every circumstance, just change it to a different value.</p>

<p>I'm using a Samsung Galaxy Note 4</p>

<p>I tried this solution that sets the camera orientation before taking photos: <a href="https://stackoverflow.com/questions/23205759/setting-android-photo-exif-orientation">Setting Android Photo EXIF Orientation</a></p>

<pre><code>Camera c = Camera.open();
c.setDisplayOrientation(90);

Camera.Parameters params = mCamera.getParameters();
params.setRotation(0); // tried 0, 90, 180
c.setParameters(params);
</code></pre>

<p>but it doesn't influence the resulting EXIF data, its still always 0</p>

<p>I also tried these solutions where the image is rotated after it is taken: <a href="https://stackoverflow.com/questions/13245556/exif-orientation-tag-value-always-0-for-image-taken-with-portrait-camera-app-and">EXIF orientation tag value always 0 for image taken with portrait camera app android</a></p>

<p>and while this rotates the photo, the EXIF orientation is still always 0.</p>

<p>I also tried setting the EXIF data directly: <a href="https://stackoverflow.com/questions/23762133/how-to-save-exif-data-after-bitmap-compression-in-android">How to save Exif data after bitmap compression in Android</a></p>

<pre><code>private Camera.PictureCallback mPicture = new Camera.PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        final File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE, "");
        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);

            ExifInterface exif = new ExifInterface(pictureFile.toString());
            exif.setAttribute(ExifInterface.TAG_ORIENTATION, "3");
            exif.saveAttributes();

            fos.write(data);
            fos.close();

            //upload photo..
        }
    }
}
</code></pre>

<p>but EXIF Orientation is still 0 after uploading.</p>

<p>I have also looked at these solutions:</p>

<p><a href="https://stackoverflow.com/questions/5574561/exif-data-tag-orientation-always-0">Exif data TAG_ORIENTATION always 0</a></p>

<p><a href="https://stackoverflow.com/questions/27732781/how-to-write-exif-data-to-image-in-android">How to write exif data to image in Android?</a></p>

<p><a href="https://stackoverflow.com/questions/20478765/how-to-get-the-correct-orientation-of-the-image-selected-from-the-default-image">How to get the Correct orientation of the image selected from the Default Image gallery</a></p>

<p><a href="https://stackoverflow.com/questions/28379130/how-to-set-camera-image-orientation">how to set camera Image orientation?</a></p>

<p>but they all involve correcting the orientation by rotating, which doesn't influence the EXIF data, or setting the EXIF data directly which doesn't seem to work.</p>

<p>How can I change the file's EXIF orientation data from 0 to 3?</p>

<p>UPDATE:</p>

<p>here is my upload code:</p>

<pre><code>Bitmap sBitmap = null;
final File sResizedFile = getOutputMediaFile(MEDIA_TYPE_IMAGE, "_2");
try {
    sBitmap = BitmapFactory.decodeStream(new FileInputStream(pictureFile), null, options);
} catch (FileNotFoundException e) {
    Log.e("App", "[MainActivity] unable to convert pictureFile to bitmap");
    e.printStackTrace();
    return;
}

// ... compute sw and sh int values

Bitmap sOut = Bitmap.createScaledBitmap(sBitmap, sw, sh, false);
Bitmap rotatedBitmap = rotateBitmap(sOut, 3);
FileOutputStream sfOut;
try {
    sfOut = new FileOutputStream(sResizedFile);
    rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, sfOut);
    sfOut.flush();
    sfOut.close();
    sBitmap.recycle();
    sOut.recycle();
    rotatedBitmap.recycle();
} catch (Exception e) {
    Log.e("App", "[MainActivity] unable to save thumbnail");
    e.printStackTrace();
    return;
}
// upload small thumbnail
TransferObserver sObserver = transferUtility.upload(
            "stills/small",        /* The bucket to upload to */
            filename + ".jpg",     /* The key for the uploaded object */
            sResizedFile           /* The file where the data to upload exists */
);
</code></pre>