您的位置:首页 > 其它

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

2012-05-25 14:07 405 查看
/** 返回查询的数据以及最新数据,将其装入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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: