SQLiteException BLOB kann nicht in Zeichenfolge konvertiert werden, wenn der Kontakt ein Foto hat. Android

In meinem Code aktualisiere ich Kontaktinformationen wie Name, Adresse, E-Mail und Foto. Wenn Kontakt kein Foto haben alles OK. Aber nachdem ich ein Foto für den Kontakt zugewiesen habe, erhalte ich android.database.sqlite.SQLiteException: unbekannter Fehler: BLOB kann bei jedem Aktualisierungsvorgang nicht in einen String konvertiert werden.

Mein Code zum Hinzufügen eines Fotos zum Kontakt

Bitmap bit =getBitmap();
                    ByteArrayOutputStream streamy = new ByteArrayOutputStream(); 
                    bit.compress(CompressFormat.PNG, 0, streamy); 
                    byte[] photo = streamy.toByteArray();

                    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, photo); 
                    values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); 

                    try {
                        if (getPhotoUri(rawContactId) != null) {
                            ContactHelper.context.getContentResolver().update(ContactsContract.Data.CONTENT_URI, values,
                                    String.format("%s = ?", ContactsContract.Data.RAW_CONTACT_ID), new String[] {String.format("%d", rawContactId)});
                        } else {
                            ContactHelper.context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values);
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }

Mein Code zum Ändern des Kontaktnamens

        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        ops.add( ContentProviderOperation.newUpdate( Data.CONTENT_URI )
                .withSelection( Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'",
                        new String[] { String.valueOf( rawContactId ) } )
                        .withValue( ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, contact.getName() )                       
                        .build() );

        try {
            ContentResolver cr = context.getContentResolver();
            cr.applyBatch(ContactsContract.AUTHORITY, ops);
        } catch (Exception e) {
            e.printStackTrace();
        }

Antworten auf die Frage(1)

Ihre Antwort auf die Frage