Serving up Images through a Content Provider in Android
So in my app, the user will find images, kind of like the concept art feature in video games. I want these images to be able to be zoomed, shared, and whatever-ed - like in the gallery app. What's the best way to display them? I think the right way to do this is to send a Intent.ACTION_VIEW with a type of image/png, so any p开发者_开发技巧rogram can get it....
But in that case, the images need to be available to any application, they can't be a resource, right? (Because then they wouldn't be available to other apps.) So they need to be available via a Content Provider...
I don't think I can just stick them in the default media Content Provider... because wouldn't they then be discoverable through the gallery app? I want the user to 'unlock' them over time. So I need to build my own content provider, and publish the images through that, right? What's the best way to make a Content Provider that can serve up images (and videos, audio, maybe contacts or other types of objects)?
I would suggest you create your own ContentProvider and handle all business logic there. Images won't be accessible to the gallery app unless they are inserted into the Media Content Provider. You can do this by a manual insert performed within your Content Provider or let the MediaScanner automatically find the files, if you store them in a public directory on the device, and insert them over time.
Why don't you just copy the image to the external storage?
After copying it you can update the Media Content provider. How to do it is explained in this question.
You can copy your images into public media directory, then initialise MediaScanner scan process, and then this images will be accessible from Gallery app
Plz go through this link.... http://developer.android.com/guide/topics/providers/content-providers.html#creating.. this could help you start the things.. you need to store your images in sqlite db .. and share the db with other applications in form of Content Provider.
精彩评论