我正在接受来自ContactsContract.Contacts的名字和电话号码的时间......我意识到他们已经更新了API,但我在这里碰到了我的头。我把我的代码放在OnClickListener和OnStartActivity下面...这个名字很好但是我无法得到这个数字......在这个问题上敲了4个小时,到处搜索。有人能给我一块骨头吗?
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.bCallContacts:
Intent i = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(i, PICK_CONTACT);
break; }
private Cursor getContact(Uri uri) {
// Run query
Cursor c = managedQuery(uri, null, null, null, null);
return c;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data)
{
super.onActivityResult(requestCode, resultCode, data);
Cursor c = getContact(data.getData());
if (c.moveToFirst())
{
String name =
c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME) );
callName.setText(name);
String phoneNumber = c.getString(c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
callNum.setText(phoneNumber);
}
}
答案 0 :(得分:0)
这会有用吗?不是我的代码我在另一页上找到了它 get contact info from android contact picker
if (Integer.parseInt(cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
// Do something with phones
}
pCur.close();
}