3

Are there any possibilities to extract contacts in some of the following formats, vCard, hCard or json/xml, using the standard Android API?

  • 1
    I think [this](http://code.google.com/p/vcardio/) will help you. This is an open-source project on "import/export contacts from/to a vCard (vcf) file". – Michaël Oct 19 '09 at 13:15

3 Answers3

4
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();

Above code can be used to export the contacts in vcf format. Read all the contacts from the fileInputStream object "fis".

Also, don't forget to add the permissions in the manifest file -

<uses-permission android:name="android.permission.READ_CONTACTS" />

Can anyone help with importing the same .vcf file to the Android using some API?

Prateek Jain
  • 1,234
  • 14
  • 24
2

i believe CONTENT_VCARD_URI is what you're looking for, at least for android 2.0 (api level 5).

i just lucked up and found it.

jason gilbert
  • 163
  • 1
  • 1
  • 7
0

Android contacts are synced with the Gmail contacts, and for those, there is an API. Conversion from the data you get back from there, is another matter.

Schildmeijer
  • 20,702
  • 12
  • 62
  • 79
Alister Bulman
  • 34,482
  • 9
  • 71
  • 110