1

我在 Android 中工作,我想知道如何找出电话号码的联系人姓名。

BroadcastReceiver我有这个:

String phonenr=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

我需要此电话号码的联系人姓名(全名 - 名字 + 姓氏,如果有)。

谢谢!

4

2 回答 2

1

你可以试试这个链接

 Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
     resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME} .....)

像这样使用下面的函数:

  Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode("your receive phone number"));
  Cursor phones = getContentResolver().query(uri, new String[]{PhoneLookup.DISPLAY_NAME},null,null,null);
        while (phones.moveToNext())
        {
            //it returns contact name
            String name=phones.getString(phones.getColumnIndex(PhoneLookup.DISPLAY_NAME));
        }
于 2012-04-23T11:51:34.280 回答
0

看看这个检索联系信息

 //query for the people in your address book
    Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null,People.NAME + " ASC");
    startManagingCursor(cursor);

    //bind the name and the number fields
    String[] columns = new String[] { People.NAME, People.NUMBER };
    int[] to = new int[] { R.id.name_entry, R.id.number_entry };
    SimpleContactAdapter mAdapter = new SimpleContactAdapter(this, R.layout.list_entry, cursor, columns, to);
    this.setListAdapter(mAdapter);
于 2012-04-23T11:59:33.067 回答