Ploue Posted September 29, 2010 Share Posted September 29, 2010 Bonjour. J'ai un petit souci pour ajouter une photo à un contact du répertoire. J'ai beau cherché je n'y arrive pas, donc je m'en remet à vos compétences ! J'ai (entre autres) essayé deux méthodes : - une personnelle, en essayant de faire comme pour les autres champs d'un contact (nom, téléphone, ...). ArrayList ops = new ArrayList(); [...] ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) .withValueBackReference(ContactsContract.Data.IS_SUPER_PRIMARY, 1) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, getBytes(c.photo)) .build()); [...] getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); - un trouvée sur le web qui, si j'ai compris, semble marcher (trouvée dans la discussion http://groups.google.com/group/android-developers/browse_thread/thread/133816827efc8eb9/?pli=1). public void setPhoto(int rawContactId, byte[] photo) { ContentValues values = new ContentValues(); int photoRow = -1; String where = ContactsContract.Data.RAW_CONTACT_ID + " == " + rawContactId; Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, where, null, null); int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID); if(cursor.moveToFirst()){ photoRow = cursor.getInt(idIdx); } cursor.close(); values.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId); 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(photoRow >= 0){ getContentResolver().update (ContactsContract.Data.CONTENT_URI, values, ContactsContract.Data._ID + " = " + photoRow, null); } else { getContentResolver().insert (ContactsContract.Data.CONTENT_URI, values); } } Je précise que la méthode getBytes que j'utilise fonctionne, puisque en utilisant BitmapFactory.decodeByteArray(...) j'arrive à obtenir une image. Mais aucune des deux ne veux marcher. Voila si quelqu'un a une piste pour me faire avancer ... merci :) Link to comment Share on other sites More sharing options...
jimmy Posted December 14, 2010 Share Posted December 14, 2010 Bonjour, As tu touvé une solution a ton problème? Je suis confronté au problème inverse... Je cherche a récupérer la photos d'un contact, pour le moment j'y arrive pas si la photos viens de facebook. Aurais tu une idée? Merci Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.