When trying to get the ExifInterface I keep seeing a Raw image not detected error message.
ExifInterface exifInterface = new ExifInterface(filepath);
int rotation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);
Does anyone know what could be causing this?
I am getting it from a Uri but I know the filepath exists
Those statements are mutually contradictory. A Uri
is not a file. If the scheme of the Uri
is file
, then and only then can you get a filesystem path to the file, by means of getPath()
. If the scheme is anything else, such as content
, then you cannot get a filesystem path, because there is no requirement that there be a file. For example, a Uri
of http://stackoverflow.com/questions/42930509/exifinterface-jni-raw-image-not-detected-error
does not mean that the Android device has a file at /questions/42930509/exifinterface-jni-raw-image-not-detected-error
.
The ExifInterface
from com.android.support:exifinterface
(e.g., where the current latest version is 25.3.0) has a constructor that takes an InputStream
. Create a ContentResolver
(via getContentResolver()
on a Context
, such as your Activity
). Call openInputStream()
on that ContentResolver
, supplying the Uri
(works for both file
and content
schemes). Pass that InputStream
to the library's ExifInterface
constructor. This simultaneously ensures that you do not cause security problems for your users and avoids having to worry about getting a filesystem path for the content that you wish to examine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With