What you should do:
BroadcastReceiver
s are not designed for getting info back, instead you can implement a pattern just like the Contacts APIs do it, by implementing your own ContentProvider.
Create a ContentProvider in your app, to allow other apps to query on your ContentProvider just like they do on the Contacts ContentProvider.
See tutorial.
You need to design how you want your content uris to look like, for example:
vnd.android.cursor.item/my_app/contact
to get info about a single contact
And you should also consider adding custom permission to your <provider>
in your manifest, so also permitted apps can access your data.
Original Answer:
If you already have an Activity
for viewing a contact, in your AndroidManifest
, add the following intents:
<activity
android:name="..."
...>
<intent-filter>
<action android:name="com.android.contacts.action.QUICK_CONTACT" />
<action android:name="android.provider.action.QUICK_CONTACT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/contact" />
<data android:mimeType="vnd.android.cursor.item/person" />
</intent-filter>
<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" />
</intent-filter>
</activity>
You'll need to properly handle incoming intents with those mimetypes and data uris in your Activity
.
You can an example in the Android system Contacts app manifest: https://android.googlesource.com/platform/packages/apps/Contacts/+/master/AndroidManifest.xml#307
You can test your implementation by adding a widget
called "Contact 1x1
" (the name may vary depending on the device) to your homescreen, and selecting which contact the widget should launch.
When clicking this widget it should call one of the above intents.