让Flutter应用程序接受传入意图

3
Flutter for Android developers文档详细介绍了如何使Flutter应用程序接受Android意图,并提供了一个接受分享意图的代码示例。我已经复制并且它运行得很好。
但是,我现在正在尝试让我的应用程序接受其他类型的意图,特别是编辑联系人意图,以便当我使用默认电话应用程序并单击联系人时,我的应用程序被建议完成操作。
我尝试了所有可能的<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.

我做错了什么?


嗨,这可能对你有所帮助,请查看以下网址: https://muetsch.io/how-to-receive-sharing-intents-in-flutter.html - undefined
2个回答

3

为了后人,基于Marmor的回答来展示具体步骤:

$ adb logcat | grep ActivityTaskManager

[...]
04-01 18:09:27.306  1384  4229 I ActivityTaskManager: START u0 {act=android.intent.action.INSERT_OR_EDIT typ=vnd.android.cursor.item/contact cmp=android/com.android.internal.app.ResolverActivity (has extras)} from uid 10065
[...]

所以我需要做的就是将这段代码添加到我的 AndroidManifest.xml 文件中:

<intent-filter>
  <action android:name="android.intent.action.INSERT_OR_EDIT"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:mimeType="vnd.android.cursor.item/contact"/>
</intent-filter>

3

这取决于您使用的联系人应用程序。

每个设备都可以配备一个制造商特定的联系人应用程序(例如Samsung Contacts),

Google提供的应用程序(Google Contacts),

服务提供商可能会安装自己的联系人应用程序,

或者用户可能正在使用从Google Play安装的应用程序(例如Contacts +)。

每个此类应用程序都可以选择通过其他应用程序可能捕获的意图启动编辑器,或者只是启动其自己内置的编辑器而不涉及意图系统。

如果有要捕捉的意图,您可以通过检查LogCat并过滤到标记ActivityManager来找出它,它显示在设备上抛出的所有意图,因此您可以研究它以找出需要捕捉的意图具体信息。


哇!太棒了!完美地运行了! - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接