Android - 与内容提供者的 Intent 匹配

标签 android android-intent android-contentprovider

来自阅读Intent文档,我看到它可用于启动 Activity 、服务或发送广播。

我想问一下Intents和Content Provider有什么关系。我使用了日历和联系人内容提供程序(在 Common Intents 之后),但那些仍然使用 startActivity。我问是因为 PackageManager 有一个名为 queryIntentContentProviders 的 API,评论如下:

Retrieve all providers that can match the given intent.

我想问一下, Intent 与内容提供者匹配的用例是什么。

最佳答案

因为这是作为 API 级别 19 (KitKat) 的一部分添加的,所以我猜这是与 Storage Access Framework 一起使用的.

  • The interaction starts when an application (in this example, a photo app) fires the intent ACTION_OPEN_DOCUMENT or ACTION_CREATE_DOCUMENT. The intent may include filters to further refine the criteria—for example, "give me all openable files that have the 'image' MIME type."
  • Once the intent fires, the system picker goes to each registered provider and shows the user the matching content roots.

示例内容提供者定义如下:

    <provider
        android:name="com.example.android.storageprovider.MyCloudProvider"
        ...
        android:enabled="@bool/atLeastKitKat">
        <intent-filter>
            <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
        </intent-filter>
    </provider>

这是迄今为止我见过的唯一一个 Intent-to-Content-Provider 匹配的例子。

实际上,我不认为 Content Provider 之前可以定义 intent-filters,尽管我可能错了。

关于Android - 与内容提供者的 Intent 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24748661/

相关文章:

java - 限制android中的成本转换?

android - 如何获取和取消 PendingIntent?

java - 非法参数异常 : Unknown URL content://CONTENT

android - ProcessLifecycleOwner 未在 Application 类中提供生命周期回调

在 ProviderTestCase2 中找不到 Android 资源

java - 将 XML 与 Activity 的 setContentView() 一起使用

android - Stripe-Android SDK 不符合 Google Play 商店的用户数据和移动垃圾软件政策

android - 如何将图像从android上传到Cloudinary?

相机 Intent 后Android崩溃

android - 如何验证系统中的其他应用程序是否为正版?