Making a Flutter app accept incoming intents

1,527

Solution 1

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.

Solution 2

For posterity, building on marmor's answer above to show the concrete steps:

$ 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
[...]

So all I had to do was add this to my 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>
Share:
1,527
J. V.
Author by

J. V.

Updated on December 15, 2022

Comments

  • J. V.
    J. V. over 1 year

    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?

  • J. V.
    J. V. about 4 years
    Wow! Brilliant! Worked perfectly!