我想在不写任何字节流的情况下交换两个联系人的个人资料图片!我想知道是否可以使用 contentResolver 更新 PHOTO_FILE_ID、PHOTO_ID、PHOTO_THUMBNAIL_URI 和 PHOTO_URI。甚至可能吗?
这是我尝试过的代码(不可运行,我只是复制了总代码的某些部分):这就是我阅读信息的方式:
String[] projection = new String[]{ ContactsContract.Data._ID,
ContactsContract.CommonDataKinds.StructuredName.PHOTO_FILE_ID,
ContactsContract.CommonDataKinds.StructuredName.PHOTO_ID,
ContactsContract.CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI,
ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI};
Cursor cursor = this.contentResolver.query(ContactsContract.Data.CONTENT_URI, projection, ContactsContract.Data.MIMETYPE + " LIKE ?",
new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }, null);
if( cursor.moveToFirst() ){
long ID = cursor.getLong( cursor.getColumnIndex(
ContactsContract.Data._ID) );
Integer photoFileID = cursor.getInt( cursor.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.PHOTO_FILE_ID) );
Integer photoID = cursor.getInt( cursor.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.PHOTO_ID) );
String photoThumbnailURI = cursor.getString( cursor.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) );
String photoURI = cursor.getString( cursor.getColumnIndex(
ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI) );
}
cursor.close();
这就是我尝试在另一个联系人中写入信息的方式:
ContentValues contentValues = new ContentValues();
contentValues.put(ContactsContract.CommonDataKinds.StructuredName.PHOTO_FILE_ID, photoFileID);
contentValues.put(ContactsContract.CommonDataKinds.StructuredName.PHOTO_ID, photoID);
contentValues.put(ContactsContract.CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI, photoThumbnailURI);
contentValues.put(ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI, photoURI);
String where = ContactsContract.Data._ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " LIKE ?";
String[] params = new String[] { String.valueOf(ID),
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };
this.contentResolver.update(ContactsContract.Data.CONTENT_URI, contentValues, where, params);
如果我运行这个脚本,调试器会告诉我这些列是无效的......任何想法如何以另一种方式更新照片细节?