2

I am writing an Android app which handle images on device.

I open the file descriptor of images using ContentResolver's openFileDescriptor(). But it throws an exception which I can't find from Android API doc for some images. It works fine for most images. About the problematic images, I can see the images without problem in the default gallery app.

Is there someone who knows why it happens?

Fatal Exception: java.lang.IllegalStateException: java.io.IOException: Failed to redact
 /storage/emulated/0/DCIM/60s-70s/a2acf4b43dd94f609d605dacc6f0a2e0.jpg
at android.os.Parcel.createExceptionOrNull(Parcel.java:2393)
at android.os.Parcel.createException(Parcel.java:2369)
at android.os.Parcel.readException(Parcel.java:2352)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:781)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1986)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1801)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1634)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1581)
--- snip ---

My code:

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                        val pfd = mContentResolver.openFileDescriptor(
                            Uri.parse(strContentUri),
                            "r"
                        )
     // strContentUri is like "content://media/external/images/media/21052"
12
  • You should first tell how you obtained strContentUri. If you used an intent action and onActivityResult then post both. If you saved the uri string and used it later then tell so. Also tell Android version of used device.
    – blackapps
    May 4, 2021 at 14:59
  • I can see the images without problem in the default gallery app. You probable first see a small thumbnail. But can you open them in full size? Maybe the file is meanwhile deleted but the media store is unaware of it.
    – blackapps
    May 4, 2021 at 15:05
  • /storage/emulated/0/DCIM/60s-70s/a2acf4b43dd94f609d605dacc6f0a2e0.jpg Did you use a classic file explorer to have a look at that path?
    – blackapps
    May 4, 2021 at 15:07
  • 1
    1. I obtained strContentUri from query(). 2. The file is definitely not deleted, I can see the image in fullsize. 3. I can see the picture from default gallery app and file explorer in Galaxy S10. I did some experiments about it after I post this question. It seems that the problem is definitely because of the file itself. After I delete the file, I copied it from my PC to the device again. But the problem happens. You can download the file here: firebasestorage.googleapis.com/v0/b/onevideo-5a6b5.appspot.com/…
    – John Hwang
    May 6, 2021 at 1:08
  • 2
    I probably know the reason. In the exif information of this picture (and other pictures that have the same problem), the XMP information is not a complete xml structure, which causes an exception during MediaProvider parsing. The exception stack is: DatabaseUtils: Caused by: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT ?xpacket begin=...@1:52 in java.io.InputStreamReader@7447c54) DatabaseUtils: at com.android.org.kxml2.io.KXmlParser.next(KXmlParser.java:432) DatabaseUtils: at com.android.providers.media.util.XmpInterface.<init>(XmpInterface.java:87)
    – meng
    Sep 28, 2021 at 14:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.