查询以及删除通话记录的内容
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);
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);
相关文章推荐
- android 通话记录的查询与删除
- android通话记录的查询与删除
- mysql删除重复记录语句的方法 作者: 字体:[增加 减小] 类型:转载 时间:2010-06-21 我要评论 查询及删除重复记录的SQL语句,虽然有点乱,但内容还是不错的。 . .
- android 通话记录的查询与删除
- mysql查询根据一个字段或者两个字段内容重复的记录并将其全部删除
- android 通话记录的查询与删除
- 通话记录的查询与删除
- android删除和查询通话记录
- 黑马程序员——查询通话记录和删除记录
- android 通话记录的查询与删除
- 练手小项目(4)安全卫士——黑名单拦截 利用内容提供者删除通话记录
- Android之通话记录的查询、删除与插入(1)
- Android - 利用内容提供者删除通话记录
- Mariadb 分布式事务两阶段提交 binlog日志 查询日志 都记录了一些什么内容 以及恢复被丢失数据方式
- MySQL查询及删除重复记录的方法
- sql查询重复记录、删除重复记录方法
- 查询并删除重复记录的SQL语句
- sql查询重复记录、删除重复记录方法
- Oracle查询重复数据并删除,只保留一条记录
- 笔记:Oracle查询重复数据并删除,只保留一条记录