J. V.
J. V.

Reputation: 1715

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?

Upvotes: 3

Views: 2538

Answers (2)

J. V.
J. V.

Reputation: 1715

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>

Upvotes: 3

marmor
marmor

Reputation: 28229

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.

Upvotes: 3

Related Questions