Android联系人有多个电话的时候获取选中的电话:
在点击事件中加入下面代码:
Intent intent =new Intent();
intent.setAction("android.intent.action.PICK");
intent.setType("vnd.android.cursor.dir/phone_v2");
startActivityForResult(intent, 1);
在onActivityResult中写:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String telNum = "";
if (requestCode==1){
if(resultCode == Activity.RESULT_OK && data != null) {
Uri uri=data.getData();
ContentResolver reContentResolverol = getContentResolver();
Cursor cursor = reContentResolverol.query(uri, new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER}, null, null, null);
if (cursor.moveToFirst()){
//这就是你选择的电话
telNum = cursor.getString(0);
}
}
}
}
网友评论