【急急急】【Android下根据通话记录表中的字段信息查询对应的联系人图像?】

张沟老王 2012-05-28 07:20:16
求一高手写一个查询语句:只根据通话记录表中的字段信息(名字、号码),查询对应的号码在联系人中的图像(要考虑多个同名、同电话情况)?谢谢
...全文
294 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
张沟老王 2012-05-31
  • 打赏
  • 举报
回复
有没有高手帮帮我啊~
张沟老王 2012-05-29
  • 打赏
  • 举报
回复
有没有直接根据名字和电话写个多表查询,可以查询到photo_id的?多谢大家了。
xttxqjfg 2012-05-29
  • 打赏
  • 举报
回复
可以参照下这个

public class MyListView2 extends Activity {
06
07 private ListView listView;
08 //private List<String> data = new ArrayList<String>();
09 @Override
10 public void onCreate(Bundle savedInstanceState){
11 super .onCreate(savedInstanceState);
12
13 listView = new ListView( this );
14
15 Cursor cursor = getContentResolver().query(People.CONTENT_URI, null , null , null , null );
16 startManagingCursor(cursor);
17
18 ListAdapter listAdapter = new SimpleCursorAdapter( this , android.R.layout.simple_expandable_list_item_1,
19 cursor,
20 new String[]{People.NAME},
21 new int []{android.R.id.text1});
22
23 listView.setAdapter(listAdapter);
24 setContentView(listView);
25 }
26
27
28 }




 Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);先获得一个指向系统通讯录数据库的Cursor对象获得数据来源。

 startManagingCursor(cursor);我们将获得的Cursor对象交由Activity管理,这样Cursor的生命周期和Activity便能够自动同步,省去自己手动管理Cursor。

 SimpleCursorAdapter 构造函数前面3个参数和ArrayAdapter是一样的,最后两个参数:一个包含数据库的列的String型数组,一个包含布局文件中对应组件id的 int型数组。其作用是自动的将String型数组所表示的每一列数据映射到布局文件对应id的组件上。上面的代码,将NAME列的数据一次映射到布局文 件的id为text1的组件上。

注意:需要在AndroidManifest.xml中如权限:<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
fishmen26 2012-05-29
  • 打赏
  • 举报
回复
上面只搜索出 对应 email 或者 phone的 Contact_id, 然后在通过这个Contact_id 到contacts 表里面取到对应的 联系人头像。
fishmen26 2012-05-29
  • 打赏
  • 举报
回复
Uri uri;
// email query
uri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI,
Uri.encode(mKeyword));
cursor = resolver.query(uri, EMAIL_SEARCH_PROJECTION, null, null, null);
if (cursor != null) {
try {
while (cursor.moveToNext()) {
long id = cursor.getLong(ContactSummary.CONTACT_SUMMARY_COL_ID);
if (!excludeIds.contains(id) && !contactIds.contains(id)) {
contactIds.add(id);
}
}
} finally {
cursor.close();
cursor = null;
}
}
// phone number start to query the phone only if the number
// looks like a phone
if (Telephony.isPossiblePhoneNum(mKeyword)) {
if (Config.DEBUG) {
Log.v(TAG, mKeyword + " is a number");
}
uri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,
Uri.encode(mKeyword));
cursor = resolver.query(uri, PHONE_SEARCH_PROJECTION, null, null, null);
if (cursor != null) {
try {
while (cursor.moveToNext()) {
long id = cursor.getLong(ContactSummary.CONTACT_SUMMARY_COL_ID);
if (!excludeIds.contains(id) && !contactIds.contains(id)) {
contactIds.add(id);
}
}
} finally {
cursor.close();
cursor = null;
}
}
}

private static final String[] EMAIL_SEARCH_PROJECTION = new String[] {
Email.CONTACT_ID
};
private static final String[] PHONE_SEARCH_PROJECTION = new String[] {
Phone.CONTACT_ID
};
张沟老王 2012-05-29
  • 打赏
  • 举报
回复
高手都到哪里去了啊?

80,471

社区成员

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

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