Background: I am writing a camera app for a messenger program. I cannot save the captured image to persistent disk at any time. The camera must support all orientations.
If you have a content:// type of Uri, android provides APIs through ContentResolver and there’s no need to use external libraries:
public static int getExifAngle(Context context, Uri uri) {
int angle = 0;
Cursor c = context.getContentResolver().query(uri,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION },
null,
null,
null);
if (c != null && c.moveToFirst()) {
int col = c.getColumnIndex( MediaStore.Images.ImageColumns.ORIENTATION );
angle = c.getInt(col);
c.close();
}
return angle;
}
You can also read any other value you find in MediaStore.Images.ImageColumns, like latitude and longitude.
This currently doesn’t work with file:/// Uris but can be easily tweaked.