Search code examples
androidflutterandroid-intentandroid-contacts

Making a Flutter app accept incoming intents


The Flutter for Android developers docs explain how to make a Flutter app accept incoming Android intents, and give a code example for accepting Share intents. I've reproduced it and it works great.

But I'm now trying to make my app accept other types of intents, specifically the Edit contact intent, so that when I use the default Phone app and click on a contact, my app is suggested to complete the action.

I've tried all possible combinations of <intent-filter> I could find after googling and searching GitHub, but nothing could get it to work. To give a few:

<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.

What am I doing wrong?


Solution

  • It depends on the Contacts app you're using.

    Each device can ship with a maker-specific contacts app (e.g. Samsung Contacts), a Google provided app (Google Contacts), the service provider may install their own Contacts app, or the user might be using an app installed from Google Play (e.g. Contacts+).

    Each such app may choose to launch the editor via an intent other apps may catch, or just launch it's own built-in editor without involving the intent system.

    If there is an intent to be catch, you can find out what that is by checking LogCat, filtering to the tag ActivityManager, it shows all intents being thrown on the device, so you can study it to find out what are the intent specifics you need to catch.