多个 ContentProvider 可以提供相同的 URI 吗?
在 Android 上查询 ContentProvider 时,可以通过提供该 ContentProvider 的“内容 URI”来指定感兴趣的 ContentProvider。当多个 ContentProvider 故意提供相同的 URI 时会发生什么?还是恶意的?
当尝试在手机上打开图片时,我看到它提示可以“处理”图像的应用程序。这里也会发生同样的事情吗?
When querying a ContentProvider on Android, one specifies the ContentProvider of interest by providing the "content URI" for that ContentProvider. What happens when multiple ContentProvider's serve that same URI, either intentionally? or maliciously?
When trying to open a pic on my phone, I've seen it prompt with apps that can "handle" the image. Will the same kind of thing happen here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多个 ContentProvider 无法做到这一点。第一个使用其清单中的元素注册内容提供程序的应用程序可以控制 URI 模式。我非常确定,如果您尝试添加另一个使用相同 URI 模式的提供程序,您将会收到安装错误。 Android 会跟踪提供者和 URI。
当您看到多个应用程序处理文件或情况的提示时,这是因为这些应用程序指定了一个包含子项的
android.intent.category.CATEGORY_ALTERNATIVE 或 android.intent-category.CATEGORY_SELECTED_ALTERNAVE。本质上,一个或多个应用程序正在声明自己是子级中指定的操作的替代方案。这使得用户可以有多种选择来处理一种数据类型。
提供替代方案是有意义的:用户可能想要编辑图片、通过 Twitter 分享或通过电子邮件发送。
请注意,两个内容提供者可以执行相同的操作,但它们不能使用相同的 URI。应用程序必须有意识地选择使用哪一个,或者提供某种在两者之间进行选择的机制。
Multiple ContentProviders can't do this. The first application that registers a content provider using the element in its manifest has control over the URI pattern. I'm pretty sure that you'll get an installation error if you try to add another provider that uses the same URI pattern. Android keeps track of providers and URIs.
When you see a prompt with multiple apps for handling a file or situation, that's because the apps have specified an with a child that includes
android.intent.category.CATEGORY_ALTERNATIVE or android.intent-category.CATEGORY_SELECTED_ALTERNATVE. In essence, the app or apps are declaring themselves to be alternatives to the action specified in the child. This allows the user to have multiple choices for handling a type of data.
It makes sense to provide alternatives: a user might want to edit a picture, share it via Twitter, or e-mail it.
Note that two content providers can do the same thing, but they can't use the same URI. An app has to make a conscious choice of which one to use, or provide some mechanism of choosing between the two.