0

我能够检索联系人,但发生点击特定联系人错误这是我的代码:

contactButton.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(intent, requestCode);
  }
});

对于 onActivity 结果:

protected void onActivityResult(int request_Code, int resultCode, Intent data) {
  // TODO Auto-generated method stub
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == request_Code) {
    if (resultCode == RESULT_OK) {
      Uri contactData = data.getData();
      Cursor c = managedQuery(contactData, null, null, null, null);
      if (c.moveToFirst()) {
        String id = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
        String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
        if (hasPhone.equalsIgnoreCase("1")) {
          Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);
          phones.moveToFirst();
          String phn_no = phones.getString(phones.getColumnIndex("data1"));
          String name = c.getString(c.getColumnIndex(StructuredPostal.DISPLAY_NAME));
          Toast.makeText(this, "contact info : " + phn_no + "\n" + name, Toast.LENGTH_LONG).show();
        }
      }
    }
  }
}
4

0 回答 0