Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 976
Dennis Avatar asked Dec 04 '12 03:12

Dennis


People also ask

How do I transfer contact info with NFC?

To Transfer Individual Contacts Keep both the phones closed. Touch the both of the NFC devices together and to share the contact touch anywhere on the screen, there will be a gentle vibration to indicate that the NFC has engaged.

Can you transfer data through NFC?

Stay organized with collections Save and categorize content based on your preferences. Android allows you to transfer large files between devices using the Android Beam file transfer feature. This feature has a simple API and allows users to start the transfer process by simply touching devices.


1 Answers

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.

like image 188
NFC guy Avatar answered Sep 20 '22 15:09

NFC guy