@Override
public void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1&&resultCode==Activity.RESULT_OK){
Uri contactData=data.getData();
Cursor cursor=managedQuery(contactData,null,null,null,null);
String phoneNumber="no number";
String name="no name";
String contactId="no ID";
if(cursor.moveToFirst()){
contactId=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
name=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Cursor phones=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+" = "+contactId, null, null);
if(phones.moveToFirst()){
phoneNumber="No Number";
phoneNumber=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
}
TextView textView=(TextView)this.findViewById(R.id.text);
textView.setText(name+" "+phoneNumber+contactId+"");
cursor.close();
}
}
上面代码中phones能正常返回一个Cursor吗?最后的输出结果,name和contactId是正常的,就phoneNumber输出的是"no number",如何能让phoneNumber输出正常的结果(就是号码)。(个人思考后觉得有可能是phones没有正确返回,而且下面的phones.moveToFirst()返回的值是false)本人新手,对于安卓还很生疏,望解答。