android - 让 Flutter 应用程序接受传入的 Intent

标签 android flutter android-intent android-contacts

Flutter for Android developers文档解释了如何让 Flutter 应用程序接受传入的 Android Intent ,并给出了接受 Share Intent 的代码示例。我已经复制了它并且效果很好。

但我现在正在尝试让我的应用程序接受其他类型的 Intent ,特别是编辑联系人 Intent ,这样当我使用默认电话应用程序并点击在联系人上,建议我的应用完成操作。

我已经尝试了 <intent-filter> 的所有可能组合在谷歌搜索和搜索 GitHub 后我可以找到,但没有任何东西可以让它工作。举几个例子:

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="vnd.android.cursor.item/person"/>
    <data android:mimeType="vnd.android.cursor.item/contact"/>
    <data android:mimeType="vnd.android.cursor.item/raw_contact"/>
    <data android:mimeType="vnd.android.cursor.item/phone"/>
    <data android:mimeType="vnd.android.cursor.item/phone_v2"/>
</intent-filter>

<intent-filter>
    <action android:name="android.intent.action.GET_CONTENT"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="vnd.android.cursor.item/person" android:host="contacts"/>
    <data android:mimeType="vnd.android.cursor.item/contact" android:host="contacts"/>
    <data android:mimeType="vnd.android.cursor.item/raw_contact" android:host="contacts"/>
</intent-filter>

<intent-filter >
    <action android:name="android.intent.action.EDIT" />
    <category android:name="android.intent.category.DEFAULT" />
    <data
        android:host="contacts"
        android:mimeType="vnd.android.cursor.item/person" />
    <data
        android:host="com.android.contacts"
        android:mimeType="vnd.android.cursor.item/contact" />
    <data
        android:host="com.android.contacts"
        android:mimeType="vnd.android.cursor.item/raw_contact" />
</intent-filter>

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.APP_CONTACT"/>
</intent-filter>

etc.

我做错了什么?

最佳答案

这取决于您使用的通讯录应用。

每台设备都可以附带制造商特定的联系人应用程序(例如三星联系人), Google 提供的应用程序(Google 通讯录), 服务提供商可以安装他们自己的联系人应用程序, 或者用户可能正在使用从 Google Play 安装的应用程序(例如 Contacts+)。

每个这样的应用程序都可以选择通过其他应用程序可能捕获的 Intent 来启动编辑器,或者只启动它自己的内置编辑器而不涉及 Intent 系统。

如果有intent要被catch,可以通过LogCat查到是什么,过滤到ActivityManager标签,它显示了设备上抛出的所有intent,可以研究它可以找出您需要捕捉的 Intent 细节。

关于android - 让 Flutter 应用程序接受传入的 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60966759/

相关文章:

Android,如何从其他方法显式调用 onCreate()?

android - 在 android 中谈论来电显示

android - 应用程序进入后台后如何导航回特定 Activity ?

java - OpenGL ES,向圆添加纹理

java - 使用 Retrofit2 将文件上传到 AWS S3 预签名 URL

flutter - 为什么在flutter中使用provider时不执行class的构造函数?

dart - 单击 TextField 小部件时 Flutter 小部件重建

java - 无法在 Android 中使用带有 Intent 的已安装媒体应用程序播放音频文件

android - 在 ScrollView 中使用 Canvas 绘制的问题

dart - 禁用向下拖动以关闭 showModalBottomSheet