質問

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

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top