1

I have an application that export the phone contacts to the sdcard in a vcf format.

I am able to get all the vcards and save them in a vcf format(looping on every ContactsContract.Contacts.LOOKUP_KEY until the cursor count -1 is reached in order to put the vcard concerning each contact in a AssetFileDescriptor and then converted to an FileInputStream using getContentResolver().openAssetFileDescriptor(....) ). The problem is that now I need to save the vcards without the photo.

So any idea how to get the contacts without their photo in order to save them on the external storage in a vcf format?

Thanks in advance

Nabz
  • 390
  • 2
  • 14
  • Clone the non-photo data from existing vcards into blank vcards before storage? – Ceiling Gecko Feb 19 '14 at 13:38
  • @CeilingGecko didn't get your idea – Nabz Feb 19 '14 at 13:50
  • @AndroidNabs I think he meant you should create a new vcard for every vcard and copy all the data but the picture and save the new vcard – Ori Wasserman Feb 19 '14 at 14:08
  • @OriWasserman I got it, but don't you think it's a hard and heavy method on the device ? I am looking for a method to query all the rows of the contacts without the photo row. Is there a way to do it ? – Nabz Feb 19 '14 at 14:11

1 Answers1

2

API Level 14 +

If you check out the source for ContactsContract.java, you can see that they introduced a new way to exclude the contact photo.

/**
 * Boolean parameter that may be used with {@link #CONTENT_VCARD_URI}
 * and {@link #CONTENT_MULTI_VCARD_URI} to indicate that the returned
 * vcard should not contain a photo.
 *
 * @hide
 */
 public static final String QUERY_PARAMETER_VCARD_NO_PHOTO = "nophoto";

The constant is hidden from the API (@hide), but you can still take advantage of it.

After you get your lookup key, you can get the "nophoto" vcard Uri using the following code:

String lookupKey = cursor.getString(
                 cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri vcardUri = ContactsContract.Contacts.CONTENT_VCARD_URI
             .buildUpon().appendQueryParameter("nophoto", String.valueOf(true))
             .build();
Uri uri = Uri.withAppendedPath(vcardUri, lookupKey);


Pre API level 14

Your only solution would be to build your own vcards using the contact information.

This library might help.

Benito Bertoli
  • 25,285
  • 12
  • 54
  • 61
  • your method work like a charm, I will use the "nophoto" parameter for API>14, and I will handle the API<14 by processing the vcards using external libraries. Thanks for your help – Nabz Feb 20 '14 at 09:27