如何使用联系人ID删除特定联系人? [英] How to delete a particular contact using contact id?
本文介绍了如何使用联系人ID删除特定联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从电话中删除特定联系人.我可以删除完整的联系人.如何使用联系人ID删除特定联系人.我想删除完整的数据,包括名字,姓氏,电话号码,电子邮件,便笺等...
I am trying to delete a particular contact from phone. I can delete the full contact. How to delete a particular contact using contact id. I want to delete the full datas including firstname, last name ,phone number, email, notes, etc...
推荐答案
尝试以下代码:
final ArrayList ops = new ArrayList();
final ContentResolver cr = getContentResolver();
ops.add(ContentProviderOperation
.newDelete(ContactsContract.RawContacts.CONTENT_URI)
.withSelection(
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = ?",
new String[] { selected_contact_IDfromlist })
.build());
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Delete This Contact!");
alertDialog.setMessage("Are you Sure you want to delete this contact?");
alertDialog.setButton(getString(R.string.callLog_delDialog_yes), new DialogInterface.OnClickListener() { // DEPRECATED
public void onClick(DialogInterface dialog, int which) {
try {
cr.applyBatch(ContactsContract.AUTHORITY, ops);
background_process();
ops.clear();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// System.out.println(" length :"+i);
}
return;
} });
alertDialog.setButton2(getString(R.string.callLog_delDialog_no), (DialogInterface.OnClickListener)null); // DEPRECATED
try {
alertDialog.show();
}catch(Exception e) {
// Log.e(THIS_FILE, "error while trying to show deletion yes/no dialog");
}
这篇关于如何使用联系人ID删除特定联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文