更新联系人图片-支持Outlook等其他提供商 [英] Update contact pictures - support other providers like outlook

查看:94
本文介绍了更新联系人图片-支持Outlook等其他提供商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

底部的代码显示了如何从我的应用程序更新联系人图片.如果用户使用sim,电话和google联系人以及类似联系人,则此方法效果很好.但是,如果他使用Outlook应用程序,则Outlook应用程序会在一段时间后再次覆盖由我的应用程序设置的图像.

The code at the bottom shows how I update contact pictures from my app. This works well, if the user uses sim, phone and google contacts and similar. But if he uses the outlook app, the outlook app does overwrite the images set by my app again after some time.

我能以某种方式解决吗?我是否可以强制覆盖Outlook图片,以使Outlook同步我的新照片而不是旧照片?

Can I somehow solve that? Can I force to overwrite the outlook image as well so that outlook syncs my new photo instead of their old one?

代码

byte[] photo = ImageUtil.convertImageToByteArray(bitmap, true);
ContentValues values = new ContentValues();
int photoId = -1;
String where = ContactsContract.Data.RAW_CONTACT_ID + " == " +
        contact.getRawId() + " AND " + ContactsContract.Contacts.Data.MIMETYPE + "=='" +
        ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
Cursor cursor = MainApp.get().getContentResolver().query(
        ContactsContract.Data.CONTENT_URI,
        null,
        where,
        null,
        null);
int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID);
if (cursor.moveToFirst()) {
    photoId = cursor.getInt(idIdx);
}
cursor.close();
values.put(ContactsContract.Data.RAW_CONTACT_ID, contact.getRawId());
values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, photo);
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);

if (photoId >= 0) {
    MainApp.get().getContentResolver().update(
            ContactsContract.Data.CONTENT_URI,
            values,
            ContactsContract.Data._ID + " = " + photoId, null);
} else {
    MainApp.get().getContentResolver().insert(
            ContactsContract.Data.CONTENT_URI,
            values);
}

推荐答案

每个SyncAdapters都有一个名为supportsUploading的配置,设置为true或false. 您不应该修改通过SyncAdapter同步的帐户的RawContacts,并将supportsUploading设置为false,因为您的更改很可能很快就会被SyncAdapter覆盖.

Each SyncAdapters has a configuration called supportsUploading set to either true or false. You shouldn't modify RawContacts of accounts there were synced by a SyncAdapter with supportsUploading set to false, as most likely your change will probably get overwritten by the SyncAdapter soon after.

您可以使用以下代码检查所有SyncAdapterssupportsUploading值:

You can check the supportsUploading value of all SyncAdapters using the following code:

final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
for (SyncAdapterType sync : syncs) {
    Log.d(TAG, "found SyncAdapter: " + sync.accountType);
    if (ContactsContract.AUTHORITY.equals(sync.authority)) {
        Log.d(TAG, "SyncAdapter supports contacts: " + sync.accountType + " - supportsUploading=" + sync.supportsUploading());
    }
}

为了给由只读SyncAdapter同步的联系人设置其他图片,您可以在自己的帐户下创建一个新的RawContact(将新的RawContact与Outlook创建的现有RawContact 结合起来,然后就可以在自己的图片上设置SUPER_PRIMARY,因此'会是默认值.

In order to set a different pic to a contact synced by a read-only SyncAdapter, you can create a new RawContact under your own account (preferably under your own SyncAdapter) and join that new RawContact with the existing RawContact created by Outlook, then you can set SUPER_PRIMARY on your own picture, so it'll be the default one.

这篇关于更新联系人图片-支持Outlook等其他提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆