Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExifInterface_JNI: Raw image not detected error

Tags:

android

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?

like image 953
John Kane Avatar asked Mar 21 '17 14:03

John Kane


1 Answers

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.

like image 186
CommonsWare Avatar answered Oct 16 '22 20:10

CommonsWare