I am making an app for managing contacts. On most phones, everything works fine, but on some Xiaomi devices, I get an error when trying to delete a contact.
Here is my code to delete contact -
final ArrayList ops = new ArrayList();
final ContentResolver cr = getContext().getContentResolver();
ops.add(ContentProviderOperation
.newDelete(ContactsContract.RawContacts.CONTENT_URI)
.withSelection(ContactsContract.RawContacts.CONTACT_ID + " = ?",
new String[]{contact.getContactId()})
.build());
try {
cr.applyBatch(ContactsContract.AUTHORITY, ops);
LogUtil.log(getString(R.string.log_msg_delete, contact.getDisplayName()));
} catch (RemoteException e) {
e.printStackTrace();
} catch (OperationApplicationException e) {
e.printStackTrace();
}
I have permissions in the manifest file-
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
and asking for them in the runtime.
The problem only appears on some Xiaomi devices. On other manufacturers, everything works. Also, I checked other apps from play store and in some contact managers this issue is not present, so there should certainly be a way to fix it