简体   繁体   English

Android-在联系人列表中搜索特定的电话号码

[英]Android - search for a specific telephone number in the contacts list

I'm working on an app that use Facebook SDK. 我正在开发一个使用Facebook SDK的应用程序。 I would like to give the user the possibility to call a Facebook Friends (shown in a listview) by clicking on their name. 我想让用户可以通过单击他们的名字来呼叫Facebook朋友(显示在列表视图中)。

There's a way to start a call intent whit the number of the selected friend? 有一种方法可以启动呼叫意图,所选朋友的号码是多少? I mean, if I click on a friend who is called JESS is possible to search through the users's contacts to find out JESS's number? 我的意思是,如果我单击一个叫JESS的朋友,可以搜索用户的联系人以找出JESS的号码吗?

(I'm not asking for getting phone number through the Facebook SDK, I've read is impossible) (我不要求通过Facebook SDK获取电话号码,我无法读取)

solved whit a simple 解决了一个简单的问题

public String getPhoneNumber(String name, Context context) {
    String ret = null;
    String selection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
            + " like'%" + name + "%'";
    String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER };
    Cursor c = context.getContentResolver().query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
            selection, null, null);
    if (c.moveToFirst()) {
        ret = c.getString(0);
    }
    c.close();
    if (ret == null)
        ret = "Unsaved";
    return ret;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM