Un très étrange problème. Je suis à mettre à jour le nom de contacts par cette règle: - si le nom d'un contact commence par "bit" + espace ("bit") alors -> mettre à jour le nom du contact à name.substring (4, name.length()) , et cela signifie que le nom du contact sera mis à jour sans le "bit". Quand j'utilise name.substring à partir du numéro qui les abaisse 4 (je pense jusqu'à l'espace au nom du contact) son fonctionnement est parfait. Quand j'utilise à partir du 4 caractères le nom du contact se multiplie. Par exmaple, quand j'utilise name = name.substring (4, name.length()) alors que le nom est égal à "bit Lili" sa mise à jour à: Lili Lili.Multipliez le nom des contacts Lors de la mise à jour (ContentProviderOperation)
private void updateContact(String name) {
ContentResolver cr = getContentResolver();
String where = ContactsContract.Data.DISPLAY_NAME + " = ?";
String[] params = new String[] {name};
Cursor phoneCur = managedQuery(ContactsContract.Data.CONTENT_URI,null,where,params,null);
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
if ((null == phoneCur)) {//createContact(name, phone);
Toast.makeText(this, "no contact with this name", Toast.LENGTH_SHORT).show();
return;} else {ops.add(ContentProviderOperation.newUpdate(android.provider.ContactsContract.Data.CONTENT_URI)
.withSelection(where, params)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name.substring(4,name.length()))
.build());
}
phoneCur.close();
try {cr.applyBatch(ContactsContract.AUTHORITY, ops);}
catch (RemoteException e) {e.printStackTrace();}
catch (OperationApplicationException e) {e.printStackTrace();}}
Merci!