如何删除联系人列表中的所有联系人的Andr​​oid手机编程

如何删除联系人列表中的所有联系人的Andr​​oid手机编程

问题描述:

我想从我的应用程序,以便删除所有的一键式preSS接触任何一个可以很好的人能告诉我如何删除编程上只有一个按钮preSS全部来自Android手机的联系人?答案将是极大的AP preciated ...

I want to delete all the contact on one button press from my application so can any one nice person can told me how to delete all the contacts from android mobile programmatically on only one button press? answer would be greatly appreciated...

其实我是从几个小时上网,但没有得到任何合适的答案。这就是为什么我要发布我的问题,在这美好的论坛...感谢这样的论坛....

Actually I was surfing from a couple of hours but not got any appropriate answer. That's why I need to post my problem in this nice forum...thanks to such forum....

这是很简单的,这code将删除所有的联系人。

It is very simple, This code will remove all your contacts.

ContentResolver contentResolver = <your app context>.getContentResolver();
        Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        while (cursor.moveToNext()) {
            String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
            Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
            contentResolver.delete(uri, null, null);
        }

完成。