查询以及删除通话记录的内容

/** 返回查询的数据以及最新数据,将其装入Map中 */

private Map<String, Long> getCallTimeByWhere(final String where) {

Map<String, Long> result = new HashMap<String, Long>();
Long total = 0L;
/** 最后一次通话时长 */
Long latestTimeLen = 0L;
/** 最后一次通话时间 */
Long lastDate = null;
final Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,
new String[] {CallLog.Calls.DURATION, CallLog.Calls.DATE }, where, null,
CallLog.Calls.DEFAULT_SORT_ORDER);
startManagingCursor(cursor);
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
Long duration = 0L;
try {
duration = Long.parseLong(cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION)));
Long date = Long.parseLong(cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE)));
if (lastDate == null || lastDate < date) {
lastDate = date;
latestTimeLen = duration;
}
} catch (Exception e) {
duration = 1L;
latestTimeLen = duration;
}
total += duration;
}
Log.i("liyong", "total=" + total + "latestTimeLen=" + latestTimeLen);
result.put("result", total);
result.put("latestTimeLen", latestTimeLen);
return result;
}

/** 删除通话记录中满足where条件的数据 */
public int deleteCallData(String where) {

return getContentResolver().delete(CallLog.Calls.CONTENT_URI, where, null);

}


调用方法:

String where = "type=1 or type=2"; //删除来电和去电
ClassName.deleteCallData(where);

String where = "type=1 or type=2";
Map<String, Long> totleResult = ClassName.getCallTimeByWhere(where);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值