2012-04-11 12 views
2

Es fällt mir schwer zu verstehen, wie man Informationen von einem Kontakt erhält und wie man Informationen zu einem Kontakt legt. Kennt jemand eine gute Art zu lernen?Bitmap auf Kontaktbild setzen

Wie auch immer, zu meiner Hauptfrage. Ich habe das Kontaktbild von einem zufälligen Code, den ich im Internet gefunden habe, aber jetzt möchte ich ein neues Bitmap-Bild für meinen Kontakt erstellen. Welche Informationen benötige ich für den Kontakt (URI oder Contact_id) und es wäre toll, wenn mir jemand ein sehr einfaches und einfaches Code und eine Art Schritt geben könnte. Aber wenn Sie nicht die Zeit haben, es durchzugehen, dann sollte nur ein einfacher einfacher Code gut sein. Danke für jede Hilfe.

EDIT GOT ARBEITS CODE JETZT: Dies ist der Code, den ich verwendet:

// Update picture to contact 
     ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 

     //contactUriId is my contact URI with just contact id number at the end of the "content://..." 
     try 
     { 
      Bitmap bitmap = bmpNewContact; 
      ByteArrayOutputStream image = new ByteArrayOutputStream(); 
      bitmap.compress(Bitmap.CompressFormat.JPEG , 100, image); 

      Builder contentOp = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); 
      contentOp.withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND " + ContactsContract.Data.MIMETYPE + "=?", new String[]{String.valueOf(contactUriId), ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE}); 
      contentOp.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, image.toByteArray()); 
      ops.add(contentOp.build()); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 

     // Update 
     try 
     { 
      getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
+0

Überprüfen Sie, ob dieser Beitrag ein paar wertvolle Punkte für Sie hat. http://StackOverflow.com/Questions/2200436/Update-Contact-details-on-android – Niko

+0

Ich wollte etwas mehr heute, weil nicht die Leute. {Was auch immer} abgeschrieben? Wenn ich das mache, möchte ich es richtig machen. Aber danke für den Vorschlag. Hat jemand anderes einen Vorschlag? – BinaryNexus

Antwort

0
// Update picture to contact 
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 

    //contactUriId is my contact URI with just contact id number at the end of the "content://..." 
    try 
    { 
     Bitmap bitmap = bmpNewContact; 
     ByteArrayOutputStream image = new ByteArrayOutputStream(); 
     bitmap.compress(Bitmap.CompressFormat.JPEG , 100, image); 

     Builder contentOp = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI); 
     contentOp.withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND " + ContactsContract.Data.MIMETYPE + "=?", new String[]{String.valueOf(contactUriId), ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE}); 
     contentOp.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, image.toByteArray()); 
     ops.add(contentOp.build()); 
    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
    } 

    // Update 
    try 
    { 
     getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
    } 
    catch (Exception e) 
    { 
     e.printStackTrace(); 
    }