Are there any possibilities to extract contacts in some of the following formats, vCard, hCard or json/xml, using the standard Android API?
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With