Bonjour,
Je n'arrive pas à mettre à jour le nom de la "company" dans une fiche d'un contact existant.
Je ne trouve pas la bonne syntaxe.
Si l'information existe déjà, l'update fonctionne, mais si la "company" n'est pas renseignée, ça bloque.
Merci de votre aide.
J'ai tenté un update, mais rien :
J'ai tenté un insert, mais rien :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); Context context = getApplicationContext(); String orgWhere = ContactsContract.Contacts.DISPLAY_NAME + " = 'Test Test'"; String[] orgWhereParams = new String[] { "Test"}; orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; orgWhereParams = new String[] { "88", ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE}; ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection(orgWhere, orgWhereParams) .withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, "Test Societe") .build()); try { context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); } catch (Exception e) { }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); Context context = getApplicationContext(); String orgWhere = ContactsContract.Contacts.DISPLAY_NAME + " = 'Test Test'"; String[] orgWhereParams = new String[] { "Test"}; orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; orgWhereParams = new String[] { "88", ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE}; int rawContactInsertIndex = ops.size(); ops.add(ContentProviderOperation .newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, "Test Societe") .build()); try { context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); } catch (Exception e) { }
Partager