【问题标题】:Retrieve contact on Android with name matching given string and dial that contact's phone number在 Android 上检索名称与给定字符串匹配的联系人并拨打该联系人的电话号码
【发布时间】:2019-04-10 08:18:05
【问题描述】:

我一直难以实现检索姓名与给定字符串匹配的联系人的电话号码,然后拨打该号码。我知道这是可能的,因为许多现有的应用程序都包含此功能。如何实施?

【问题讨论】:

    标签: android contacts android-contacts contactscontract


    【解决方案1】:

    此代码获取手机中的所有联系人

    Cursor phones = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
        if (phones != null) {
            while (phones.moveToNext()) {
                String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            }
            phones.close();
    
        }
    

    将变量“name”或“phoneNumber”与您的字符串进行比较

    并且您已添加权限“android.permission.READ_CONTACTS”

    【讨论】:

    • 在调整到新的运行时权限方案后,效果很好!
    猜你喜欢
    • 2014-03-30
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多