How to beam a contact from you app (using NFC) and save it in contact list on receiving device?
Asked Answered
N

1

6

How would you beam a contact using your own app (and using Android Beam) to another device and have it saved in their contact list (i.e. the default contacts app). The contact on the sending device will be provided by the ContactsContract provider.

Preferably I don't want to have the other device running my app. The built-in contacts app (Android's default app) can beam and receive contacts. So it should be possible to beam a contact using a custom app to the built-in contacts app.

The answers to this question suggest that it's possible and that you can use the VCARD format.

Currently, my app will search for a contact by phone number, then display it in a new activity (which is the built-in contacts app). See below.

Uri uri = Uri.fromParts("tel", number.getText().toString(), "");
Log.d("ContactPicker", uri.toString());
startActivity(new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, uri));

// Example log message for the number (123)-123-1234 is "tel:(123)%20123-1234"

I'd prefer to do it this way, but don't think it's possible because I can't return the contact that was found (or the contact that was created if no existing one was found). And I need that information if I want to beam that specific contact.

I'll probably need to query all contacts, find the contact I'm looking for and save its ID.

Note: I'm using API 14


Edit

I made a proof of concept app that does this: https://github.com/dideler/HiFive

The app might be buggy. It's not maintained, but pull requests are welcome.

Newel answered 4/12, 2012 at 3:50 Comment(1)
good question! i'm interested as to if this is possible :)Undone
G
2

Yes, vCard is the way to go. It is the format that the built-in Contacts/People app will pick up. It is also the format that the app uses to store its own data, and I believe.

Gothurd answered 4/12, 2012 at 6:57 Comment(2)
Thanks for the verification! If I have to use the vCard format, is there an easy way to convert a contact's info to vCard format (or get the vCard-formatted data directly), or will I need need to write the conversion code myself?Newel
In reply to my previous comment, so far I've found: code.google.com/p/vcardio, #8036341, and https://mcmap.net/q/1917128/-android-contatcs-vcard-api.Newel

© 2022 - 2024 — McMap. All rights reserved.