android删除单个联系人,android – 如何使用联系人ID删除特定联系人?

尝试以下代码:

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");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值