开发者

Photos getting scaled automatically after updating address book

开发者 https://www.devze.com 2023-03-14 12:56 出处:网络
Here is the code I am using to write a contact PHOTO.It works.If I am quick enough after writing it to the address book and go back and read the contact, I get my picture back.

Here is the code I am using to write a contact PHOTO. It works. If I am quick enough after writing it to the address book and go back and read the contact, I get my picture back.

But, after 10 seconds or so, in the debugger you can see an alarm fire and a thread startup and after that goes away if I go read the same contact back, the PHOTO was scaled down from roughly 400x400 down to 96x96.

It looks like there is a trigger firing on the backend to scale the PHOTO after it is written. Does anyone know a way to get around this or control it? Or is there a better way of writing a PHOTO that will not cause this scaling trigger?

I am doing this in Android 2.1 on Droid.

In trying to determine if I was writing the PHOTO correctly, I saw that there was a ContactsContract.ContactsColumns interface with PHOTO_URI and PHOTO_THUMB_URI members, but I cannot find any way to get at it as the interface is protected and I cannot find any of the joins returning them. Does anyone how to use them?

    Uri uri = ContactsContract.RawContacts.CONTENT_URI;
    String[] projection = new String[] { BaseColumns._ID };
    String selection = ContactsContract.RawContacts.CONTACT_ID + "=?";
    String[] arguments = new String[] { "" + lContactID };

    Cursor cursor = resolver.query(uri, projection, selection, arguments, null);
    if (cursor != null && cursor.getCount() > 0)
    {
        while (cursor.moveToNext())
        {
            long rawContactId = cursor.getLong(0);
            int row = -1;
            Uri uri = ContactsContract.Data.CONTENT_URI;
            String[] projection = new String[] { ContactsContract.Data._ID };
            String selection = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + "='" + Contact开发者_运维问答sContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
            String[] params = new String[] { "" + rawContactId };

            Cursor cursor = resolver.query(uri, projection, selection, params, null);
            if (cursor != null && cursor.getCount() > 0)
            {
                if (cursor.moveToFirst())
                {
                    row = cursor.getInt(0);
                }
                cursor.close();
            }

            ContentValues values = new ContentValues();
            values.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId);
            values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
            values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, pic);
            values.put(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);

            if (row >= 0)
            {
                resolver.update(ContactsContract.Data.CONTENT_URI, values, ContactsContract.Data._ID + " = " + photoRow, null);
            }
            else
            {
                resolver.insert(ContactsContract.Data.CONTENT_URI, values);
            }
        }
        cursor.close();
        cursor = null;
    }


It turns out that it is the gmail.com sync adapter that is scaling the photo.

if I turn off

Settings->Accounts&Syncs->gmail.com->“Sync Contacts” the problem goes away.

Why does the sync adapter need to do this on a PHOTO it did not put there?

If that were not enough, it is not even very consistent with how it does it:

If the gmail.com contact does not previously have a picture on the server, when I write the PHOTO to the address book it is not scaled. The picture shows up on the server.

However, if the gmail.com contact previously had a picture on the server, when I write the contact to the address book the picture I just wrote is scaled to 96x96. Once again the picture shows up on the server.

So, either the sync adapter has a bug with processing the original picture, or has a bug with the update of a picture, because it does not always scale the photo. Either way, it should not be scaling the picture :(

0

精彩评论

暂无评论...
验证码 换一张
取 消