gpt4 book ai didi

android - 在 Android 中按姓名搜索联系人的电话号码

转载 作者:行者123 更新时间:2023-11-29 22:16:44 25 4
gpt4 key购买 nike

我已经在 Android 中成功实现了通过语音识别查找联系人姓名的搜索。现在我想通过语音识别找到号码。

我已经试过了 How to call Android contacts list? ,但它不适用于我的 SGS2。我认为来源是旧版本。这就是它不起作用的原因。

如何在 Android 通讯录中按姓名查找通过语音识别得出的号码?

最佳答案

    private void getContactData() {
Cursor phoneCursor = null;
contactList = new HashMap<String,String>();

try{
// 주소록이 저장된 URI
Uri uContactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;

// 주소록의 이름과 전화번호의 열 이름
String strProjection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;

// 주소록을 얻기 위한 쿼리문을 날리고 커서를 리턴
phoneCursor = getContentResolver().query(uContactsUri, null, null, null, strProjection);
phoneCursor.moveToFirst();

String name = "";
String phoneNumber = "";

// 주소록의 이름
int nameColumn = phoneCursor.getColumnIndex(Phone.DISPLAY_NAME);
// 주소록의 전화번호
int phoneColumn = phoneCursor.getColumnIndex(Phone.NUMBER);

while(!phoneCursor.isAfterLast()){
name = phoneCursor.getString(nameColumn);
phoneNumber = phoneCursor.getString(phoneColumn);

// HashMap에 data 넣음
contactList.put(name, phoneNumber);
phoneCursor.moveToNext();
}
}
catch(Exception e){
Log.e("[SmsMain] getContactData", e.toString());
}
finally{
if(phoneCursor != null){
phoneCursor.close();
phoneCursor = null;
}
}
}

这是获取联系人数据库的来源。

我通过搜索解决了。

关于android - 在 Android 中按姓名搜索联系人的电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8279703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com