在Intent Android中选择联系人后如何删除联系人

时间:2018-10-27 00:44:10

标签: java android

在Intent Android中选择联系人后,如何删除该联系人?  我尝试搜索,但找不到任何东西,谢谢!!

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
    if (intent.resolveActivity(getPackageManager()) !=null)
        startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode==1  && resultCode==RESULT_OK){
        Uri contactUri = data.getData();

    }
}

1 个答案:

答案 0 :(得分:0)

您必须使用 ContentResolver 游标查询删除特定联系人。用法如下:

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
        null, null, null, null);
 try
    {
     cr.delete(contactUri, null, null);
    }
    catch(Exception e)
    {
        System.out.println(e.getStackTrace());
    }
}