Search code examples
androiduriandroid-contentprovider

Using http / https URIs as content URIs in Android


I came upon the following issue.

My application presents the image Gallery to the user for selecting a file and then opens an input stream for reading that file and sending it over some medium. This is the code that does the work:

ContentResolver resolver = getContentResolver();            
fileStream = resolver.openInputStream(fileUri);

Everything works great when the selected image resides on the device storage (like photos taken from the camera and such) and I get a content:// scheme URI. The problem is when I select an image from my Picasa album which apparently loads the image from the Picasa servers on demand. In that case I get an https:// scheme URI and the openInputStream call fails with a FileNotFoundException "No content provider".

My question is what would be the best way to get an input stream in that case? I was thinking about opening a URL connection but I wonder if that would be the best option? I am quite unsure on whether content providers in Android can provide a better solution for this.


Solution

  • content:// urls identify a resource on the local device.

    https:// identifies content on a remote server (The picasa webserver). I assume you're seeing these because you have an HTC device where picasa is integrated into gallery by sense.

    When you get a https:// address, you'll need to go fetch the data directly from the server.
    See google-api-java-client.