Android查询通话记录

news/2025/2/12 14:09:22/
 	public static final Uri CALL_LOG_CONTENT_URI = CallLog.Calls.CONTENT_URI;//通话记录Uriprivate static final int QUERY_TOKEN = 304;public static final String[] SUMMARY_PROJECTION = new String[]{CallLog.Calls._ID,                 //IDCallLog.Calls.CACHED_NAME,         //姓名CallLog.Calls.CACHED_NUMBER_LABEL, //缓存电话标签CallLog.Calls.CACHED_NUMBER_TYPE,  //缓存电话类型(家庭电话,工作电话等)CallLog.Calls.NUMBER,           //电话号码CallLog.Calls.TYPE,             //通话类型(来电,去电,未接)CallLog.Calls.DURATION,         //通话时长CallLog.Calls.DATE,             //通话日期};

源码下载http://download.csdn.net/detail/wds1181977/7621419




2调用AsyncQueryHandler

	private final class QueryContactsHandler extends AsyncQueryHandler {public QueryContactsHandler(Context context) {super(context.getContentResolver());}@Overrideprotected void onQueryComplete(int token, Object cookie, Cursor cursor) {if (cursor == null || cursor.isClosed() || !cursor.moveToFirst()) {mStopLoadHandler.sendEmptyMessage(QUERY_NO_CONTACTS);return;}if (!getActivity().isFinishing()) {if(cursor.getCount() > 0) {mStopLoadHandler.sendEmptyMessage(QUERY_COMPLETE);} else {mStopLoadHandler.sendEmptyMessage(QUERY_NO_CONTACTS);}if(mDateTimeMap != null){mDateTimeMap.clear();mDateTimeMap = null;}mDateTimeMap = new HashMap<Long, Boolean>();long currentDate = 0;while(!cursor.isAfterLast()){long _id = cursor.getLong(CallLogUtils.ID_INDEX);long date = cursor.getLong(CallLogUtils.DATE_INDEX);date = DateTimeUtils.getStartTimeOfDay(date);if(date != currentDate){mDateTimeMap.put(_id, true);currentDate = date;} else {mDateTimeMap.put(_id, false);}cursor.moveToNext();}mContactsAdapter.changeCursor(cursor);} else {if (cursor != null && !cursor.isClosed()) {cursor.close();}}}}








3开始查询

	private void startEmptyQuery(){if (mQueryContactsHandler == null) {if(LogLevel.DEV){DevLog.e(TAG, "startEmptyQuery() failed, mQueryContactsHandler is null.");}return;}mQueryContactsHandler.cancelOperation(QUERY_TOKEN);Uri uri = CallLogUtils.CALL_LOG_CONTENT_URI;mQueryContactsHandler.startQuery(QUERY_TOKEN, null, uri, CallLogUtils.SUMMARY_PROJECTION, null, null, CallLogUtils.DEFAULT_SORT_ORDER);}

	@Overridepublic void onResume(){if(LogLevel.MARKET){MarketLog.i(TAG, "onResume...");}super.onResume();startEmptyQuery();}






4读取Cursor Java Bean CallLogInfo


	public static final int ID_INDEX = 0;public static final int CACHED_NAME_INDEX = 1;public static final int CACHED_NUMBER_LABEL_INDEX = 2;public static final int CACHED_NUMBER_TYPE_INDEX = 3;public static final int NUMBER_INDEX = 4;public static final int TYPE_INDEX = 5;public static final int DURATION_INDEX = 6;public static final int DATE_INDEX = 7;


public static CallLogInfo readCallLogInfoByCursor(Cursor cursor){if(cursor == null || cursor.isClosed()){return null;}try {CallLogInfo info = new CallLogInfo();info._id = cursor.getLong(ID_INDEX);info.name = cursor.getString(CACHED_NAME_INDEX);info.number_label = cursor.getString(CACHED_NUMBER_LABEL_INDEX);info.number_type = cursor.getString(CACHED_NUMBER_TYPE_INDEX);info.number = cursor.getString(NUMBER_INDEX);info.type = cursor.getInt(TYPE_INDEX);info.duration = cursor.getLong(DURATION_INDEX);info.date = cursor.getLong(DATE_INDEX);return info;} catch (Exception e){e.printStackTrace();return null;}}

电话记录类型

     public static final String TYPE = "type";/** Call log type for incoming calls. */public static final int INCOMING_TYPE = 1;//来电记录/** Call log type for outgoing calls. */public static final int OUTGOING_TYPE = 2;//去电记录/** Call log type for missed calls. */public static final int MISSED_TYPE = 3;//未接记录/*** Call log type for voicemails.* @hide*/public static final int VOICEMAIL_TYPE = 4;//语言信箱

默认排序

public static final String DEFAULT_SORT_ORDER = CallLog.Calls.DEFAULT_SORT_ORDER;





http://www.ppmy.cn/news/862599.html

相关文章

android 查询不同机型通话记录信息

需求&#xff1a;实现通话记录和短信同步&#xff0c;需要对应手机卡槽ID。 public List<CallRecordsEntity> getPhoneList(Context context) {try {Map<Integer, Integer> simInfo BaseApp.getInstance().getSimInfo();ContentResolver contentResolver context…

Linux文件

目录 系统级I/O 简介 接口 文件描述符fd 重定向 缓冲区 文件系统 软硬链接 动静态库 静态函数库 动态库 系统级I/O 简介 输入/输出&#xff08;I/O&#xff09;是在主存和外部设备&#xff08;磁盘驱动器、终端和网络&#xff09;之间复制数据的过程。输入操作是…

查询通话详单

j题目来源&#xff1a;牛客网编程之美栏目 登录中国联通网上营业厅 /电信/移动 后选择「自助服务」 --> 「详单查询」&#xff0c;然后选择你要查询的时间段&#xff0c;点击「查询」按钮&#xff0c;查询结果页面的最下方&#xff0c;点击「导出」&#xff0c;就会生成类…

2023/7/13 platform实现中断,led,终端输出变量

platform驱动实现 1.使用驱动代码实现如下要求 a.应用程序通过阻塞的io模型来读取number变量的值 b.number是内核驱动中的一个变量 c.number的值随着按键按下而改变&#xff08;按键中断) 例如number0按下按键number1 ,再次按下按键numberOd .在按下按键的时候需要同时将led1…

MySQL数据库表数据的基本操作

目录 1.创建表 2.插入数据 3.修改表数据 3.1、将所有员工薪水修改为5000元 ​3.2、将姓名为张三的员工薪水修改为3000元 ​3.3、将姓名为李四的员工薪水修改为4000元gender改为女 ​3.4、将王五的薪水在原有基础上增加1000元 4、MySQL字符集 1.创建表 创建员工表emplo…

渗透测试 ( 3 ) --- Metasploit Framework ( MSF )

白嫖 Metasploit Pro 2022&#xff1a;https://zhuanlan.zhihu.com/p/449836479 白嫖 Metasploit Pro 2022&#xff1a;http://t.zoukankan.com/hxlinux-p-15787814.html 好东西之 metasploit pro&#xff1a;https://www.52pojie.cn/thread-1586222-1-1.html Metasploit Pro 英…

Ubuntu 8.04 优化设置

文章中部分TIGER修改Ubuntu 8.04 LTS(长期支持版)免费光盘已经接受预定! https://shipit.ubuntu.com/ 有刻录机的最好自己刻盘,体谅人家.总纲&#xff1a;分以下几部分工作 (更新截至4月27日&#xff0c;决定停止更新&#xff0c;文章写长了就没意思了&#xff0c;眼花&#xf…

Qt/C++编写物联网管理平台21-探测器管理

一、前言 探测器在整个系统中是最核心的关键的硬件&#xff0c;终端节点硬件&#xff0c;安装有探测芯片装置&#xff0c;负责探测前端对应气体浓度&#xff0c;并记录值&#xff0c;等待控制器轮训数据回复&#xff0c;控制器信息表也是字段最多的&#xff0c;要存储位号、控…