从Android联系人获取多个数字
|
我一直在寻找如何从联系人中获取多个电话号码(例如家庭,手机,办公),但我很困惑。我将在下面添加我正在使用的代码。我希望有人能帮帮忙。谢谢
杰夫
case CONTACT_PICKER_RESULT:
Log.w(\"+DEBUG_TAG+\",\"Got the Info\");
//handle contact results
Cursor cursor = null;
String number = \"\";
String number2 = \"\";
try{
Uri result = data.getData();
//get the content id
String id = result.getLastPathSegment();
//ask for the phone number
cursor = getContentResolver().query(Phone.CONTENT_URI,
null, Phone.CONTACT_ID + \"=?\", new String[] {id},
null);
int phoneIdx = cursor.getColumnIndex(Phone.DATA);
//take the phone number
if(cursor.moveToFirst()){
number = cursor.getString(phoneIdx);
Log.v(\"+DEBUG_TAG+\",\"Got number \" + number);
}else if(cursor.moveToNext()){
number2 = cursor.getString(phoneIdx);
Log.v(\"+DEBUG_TAG+\",\"GOT NumbEr2 \"+ number2);
}
else{
Log.e(\"+DEBUG_TAG\",\"FAILED TO GET NUMBER!\");
}
}
finally{
if(cursor != null){
cursor.close();
}
EditText phNumberEditText = (EditText) findViewById(R.id.number1);
phNumberEditText.setText(number);
if (number.length() == 0){
Toast.makeText(this, \"No Phone Number For This Contact\",
Toast.LENGTH_LONG).show();
}
没有找到相关结果
已邀请:
1 个回复
碉罕城爸