如何在ContentProvider Uri表中唯一知道联系人是否存在

时间:2012-12-03 06:24:44

标签: android android-contentprovider android-sqlite

我如何检查android数据库中是否存在特定联系人以将其添加到数据库中,如果我检查联系人名称可能会出现另一个同名联系人的问题,那么任何人都可以帮助我,我的代码是:

String where = ContactsContract.Contacts.DISPLAY_NAME+" = ? ";
String[] whereArg = new String[] {displayName};

Cursor sameName = cResolver.query(ContactsContract.Contacts.CONTENT_URI, null, where, whereArg,null);

if (sameName == null || sameName.getCount() == 0) {
                    // TODO //the addContact method
                }else {

                    // do nothing, the contact is exsist

                }

0 个答案:

没有答案