SQLite 查询电话本中指定的一组Phone._ID

yitiaochongzi 2010-05-14 12:28:11
怎样getContentResolver().query(uri, null,People._ID + " in " + "(1,3,4,5,8,12)", null, null);
...全文
149 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hgz20072602 2011-11-22
  • 打赏
  • 举报
回复
Cursor c = getContentResolver().query(dataUri, //dataUri 具体的数据库表的uri地址
new String[] {Phone._ID, Phone.NUMBER, Phone.IS_SUPER_PRIMARY}, //需要查询的列
Data.MIMETYPE + "=?", //相当于SQL语句中where后面的 xxx=
new String[] {Phone.CONTENT_ITEM_TYPE}, //相当于SQL语句中where xxx=后面的 yyy
null); //sort order

怎么才能实现SQL语句中的 where xxx=yyy and ddd=fff ? 就是说比如查询的时候有两个条件 在android中的sqlite如何实现
yyy025025025 2010-05-15
  • 打赏
  • 举报
回复
Contact中的获取phone number的代码:

Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri dataUri = Uri.withAppendedPath(baseUri, Contacts.Data.CONTENT_DIRECTORY);

Cursor c = getContentResolver().query(dataUri,
new String[] {Phone._ID, Phone.NUMBER, Phone.IS_SUPER_PRIMARY},
Data.MIMETYPE + "=?", new String[] {Phone.CONTENT_ITEM_TYPE}, null);
yitiaochongzi 2010-05-15
  • 打赏
  • 举报
回复
能解释一下各个语句的作用 和 各个参数是什么吗
yyy025025025 2010-05-15
  • 打赏
  • 举报
回复
1. 首先需要了解contact数据库的结构,用ddms去手机或者模拟器的目录 data/data/com.android.provider.contact下去把数据库拉出来看下。

contact部分的数据表为:
"_id","display_name","photo_id","custom_ringtone","send_to_voicemail","times_contacted","last_time_contacted","starred","in_visible_group","has_phone_number","lookup","status_update_id","single_is_restricted"

2. 到下面的网址,有contact读取电话号码的代码,http://android.git.kernel.org/?p=platform/packages/apps/Contacts.git;a=blob;f=src/com/android/contacts/ContactsListActivity.java;h=24c7100e91d16d38da94914407360d49fadb27f9;hb=HEAD

3.
//contactId是需要查询的id号
Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri dataUri = Uri.withAppendedPath(baseUri, Contacts.Data.CONTENT_DIRECTORY);

Cursor c = getContentResolver().query(dataUri, //dataUri 具体的数据库表的uri地址
new String[] {Phone._ID, Phone.NUMBER, Phone.IS_SUPER_PRIMARY}, //需要查询的列
Data.MIMETYPE + "=?", //相当于SQL语句中where后面的 xxx=
new String[] {Phone.CONTENT_ITEM_TYPE}, //相当于SQL语句中where xxx=后面的 yyy
null); //sort order
yitiaochongzi 2010-05-14
  • 打赏
  • 举报
回复
上面的语句对吗??
heaven_wsh 2010-05-14
  • 打赏
  • 举报
回复
语句应该没错,不知lz出的是什么问题。
liqi4960710 2010-05-14
  • 打赏
  • 举报
回复
刚刚接触这种数据库!来关注学习的!呵呵
zd7451676 2010-05-14
  • 打赏
  • 举报
回复
ContentResolver content =getContentResolver().query(uri, null,People._ID + " in " + "(1,3,4,5,8,12)", null, null);
貌似没的错误。。
yitiaochongzi 2010-05-14
  • 打赏
  • 举报
回复
顶起来

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧