-1
我有一個hellva時間只是從ContactsContract.Contacts獲取名稱和電話號碼...我意識到他們更新了API,但我在這裏撞牆。我把我的代碼放在OnClickListener和OnStartActivity下面...名字很好,但是我不能得到這個號碼......一直在我的頭上敲了4個小時,然後到處搜索。有人能給我一顆骨頭嗎?從ContactsContract.Contacts獲取姓名和電話號碼。在Android?
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);
}
}