telephoto icon indicating copy to clipboard operation
telephoto copied to clipboard

Crash when using custom Uris

Open janbina opened this issue 1 year ago • 1 comments

In our app, we are using uris with custom scheme to fetch a specific type of images. They are of this form:

localdb://poiimageprovider/image-data?requestid=...

We then have a Fetcher for coil that loads the image data from database, something like

class DbUriFetcherFactory : Fetcher.Factory<Uri> {
  override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher {
    return Fetcher {
      if (data.scheme == "localdb") {
        // load data and return `SourceResult`
      } else null
    }
  }
}

This works fine with coil, but telephoto tries to access the uri using ContentResolver and crashes:

java.io.FileNotFoundException: No content provider: localdb://poiimageprovider/image-data?requestid=...
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2029)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1528)
at me.saket.telephoto.subsamplingimage.UriImageSource.peek(SubSamplingImageSource.kt:187)
at me.saket.telephoto.zoomable.coil.SubSamplingEligibilityKt.isSvg(subSamplingEligibility.kt:56)
at me.saket.telephoto.zoomable.coil.SubSamplingEligibilityKt.canBeSubSampled(subSamplingEligibility.kt:26)
at me.saket.telephoto.zoomable.coil.Resolver.toSubSamplingImageSource(CoilImageSource.kt:153)
at me.saket.telephoto.zoomable.coil.Resolver.work(CoilImageSource.kt:109)

I'm not quite sure whether this should work or not, our solution is probably not great and maybe we should actually use ContentProvider for our uris instead of Fetcher, but it worked so far 😀 For now we fixed that by using model class instead of plain Uri.

janbina avatar Sep 25 '23 15:09 janbina