通过 Android 中的内容提供程序提供图像
因此,在我的应用程序中,用户会找到图像,有点像视频游戏中的概念艺术功能。我希望这些图像能够缩放、共享以及进行任何编辑 - 就像在图库应用程序中一样。展示它们的最佳方式是什么?我认为正确的方法是发送一个带有 image/png 类型的 Intent.ACTION_VIEW,这样任何程序都可以获取它......
但在这种情况下,图像需要可用于任何应用程序,它们不能是资源,对吧? (因为这样它们就无法供其他应用程序使用。)因此它们需要通过内容提供程序提供...
我不认为我可以将它们粘贴在默认媒体内容提供程序中...因为它们不会通过图库应用程序被发现吗?我希望用户随着时间的推移“解锁”它们。所以我需要构建自己的内容提供商,并通过它发布图像,对吧?制作可以提供图像(以及视频、音频、可能是联系人或其他类型的对象)的内容提供商的最佳方法是什么?
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 program 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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议您创建自己的 ContentProvider 并在那里处理所有业务逻辑。除非将图像插入媒体内容提供程序,否则图库应用程序将无法访问图像。您可以通过在内容提供程序中执行手动插入来完成此操作,或者让 MediaScanner 自动查找文件(如果您将文件存储在设备上的公共目录中)并随着时间的推移插入它们。
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.
您可以将图像复制到公共媒体目录中,
然后初始化MediaScanner扫描过程,
然后可以从图库应用程序访问这些图像
You can copy your images into public media directory,
then initialise MediaScanner scan process,
and then this images will be accessible from Gallery app
请浏览此链接... http://developer. android.com/guide/topics/providers/content-providers.html#creating..这可以帮助您开始工作..您需要将图像存储在 sqlite 数据库中..并与其他应用程序共享数据库形式为内容提供商。
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.