gpt4 book ai didi

android - 如何从我的android联系人列表中的人名中获取电话号码

转载 作者:太空宇宙 更新时间:2023-11-03 13:33:47 26 4
gpt4 key购买 nike

我想从我的联系人列表中的姓名中获取此人的电话号码。我使用了以下代码,但效果不佳。告诉我哪里错了。

          try {                   
cursor_company =getContentResolver().query(ContactsContract.Data.CONTENT_URI,
null,ContactsContract.Data.DISPLAY_NAME+ " = " + "sidharth", null, null);
}
catch(Exception e)
{
System.out.println("this is exception "+e);
}
String phone_number;
while (cursor_company.moveToNext()) {
Phone_number =cursor_company.getString(
cursor_company.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println(" this is user no. is"+phone_number);
}
cursor_company.close();
}

当我运行下面这段代码时出现异常

android.database.sqlite.SQLiteException: no such column: bhawana: , while compiling: SELECT data_version, phonetic_name, phonetic_name_style, contact_id, lookup, data12, data11, data10, mimetype, data15, data14, data13, display_name_source, data_sync1, data_sync3, data_sync2, agg_presence.chat_capability AS contact_chat_capability, data_sync4, account_type, custom_ringtone, sp, status_updates.status AS status, data1, data4, data5, data2, data3, sns_id, data8, data9, group_sourceid, data6, account_name, data7, display_name, in_visible_group, display_name_alt, contacts_status_updates.status_res_package AS contact_status_res_package, is_primary, contacts_status_updates.status_ts AS contact_status_ts, raw_contact_id, times_contacted, contacts_status_updates.status AS contact_status, status_updates.status_res_package AS status_res_package, status_updates.status_icon AS status_icon, contacts_status_updates.status_i

最佳答案

这里是:

static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.STARRED,
ContactsContract.Contacts.TIMES_CONTACTED,
ContactsContract.Contacts.CONTACT_PRESENCE,
ContactsContract.Contacts.PHOTO_ID,
ContactsContract.Contacts.LOOKUP_KEY,
ContactsContract.Contacts.HAS_PHONE_NUMBER,
};

String name_to_search = "sidharth";

String select = "(" + ContactsContract.Contacts.DISPLAY_NAME + " == \"" +name_to_search+ "\" )";
Cursor c = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select, null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
context.startManagingCursor(c);

if (c.moveToNext())
{
String id = c.getString(0);
ArrayList<String> phones = new ArrayList<String>();

Cursor pCur = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null);
while (pCur.moveToNext())
{
phones.add(pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
Log.i("", name_to_search+ " has the following phone number "+ pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
}
pCur.close();
}

关于android - 如何从我的android联系人列表中的人名中获取电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938724/

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