gpt4 book ai didi

android - 从安卓联系人中删除联系人

转载 作者:行者123 更新时间:2023-11-29 01:12:24 26 4
gpt4 key购买 nike

我正在尝试从电话通讯录中删除联系人。该联系人已从电话联系人中删除,但未从服务器端(Google 联系人)删除,当触发 Google 联系人同步时,已删除的联系人会重新出现。下面是我的代码。

public static void deleteContact(long rawid, ContentResolver contentResolver) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
Uri uri = ContactsContract.RawContacts.CONTENT_URI
.buildUpon()
.appendQueryParameter(
ContactsContract.CALLER_IS_SYNCADAPTER,
"true")
.build();
ops.add(ContentProviderOperation
.newDelete(uri)
.withSelection(
ContactsContract.RawContacts._ID + " = ?",
new String[]{Long.toString(rawid)})
.build());

try {
contentResolver.applyBatch(
ContactsContract.AUTHORITY,
ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
}
}

最佳答案

您应该在代码中尝试将 ContactsContract.CALLER_IS_SYNCADAPTER 设置为 false。设置为 true 时,联系人将从数据库中永久删除。但是当下一次同步发生时,联系人会同步回来。 Google 同步检查已删除联系人的方式是使用已删除标志,该标志仅在您将 ContactsContract.CALLER_IS_SYNCADAPTER 设置为 false 时设置。下面是来自 ContactsProvider 类(联系人数据存储的内容提供者)的代码 fragment

if (callerIsSyncAdapter || rawContactIsLocal(rawContactId)) {
// When a raw contact is deleted, a SQLite trigger deletes the parent contact.
// TODO: all contact deletes was consolidated into ContactTableUtil but this one can't
// because it's in a trigger. Consider removing trigger and replacing with java code.
// This has to happen before the raw contact is deleted since it relies on the number
// of raw contacts.
db.delete(Tables.PRESENCE, PresenceColumns.RAW_CONTACT_ID + "=" + rawContactId, null);
count = db.delete(Tables.RAW_CONTACTS, RawContacts._ID + "=" + rawContactId, null);
mTransactionContext.get().markRawContactChangedOrDeletedOrInserted(rawContactId);
} else {
count = markRawContactAsDeleted(db, rawContactId, callerIsSyncAdapter);
}

关于android - 从安卓联系人中删除联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41988836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com