分类: 嵌入式
2011-04-28 17:07:56
表名:calls
呼叫记录有三种类型:
来电:CallLog.Calls.INCOMING_TYPE (常量值:1)
已拨:CallLog.Calls.OUTGOING_TYPE(常量值:2)
未接:CallLog.Calls.MISSED_TYPE(常量值:3)
查看源码中的声明:
android:syncable="false" android:multiprocess="false"
android:readPermission="android.permission.READ_CONTACTS"
android:writePermission="android.permission.WRITE_CONTACTS">
需要声明的权限
系统的通话记录,是通过 ContentProvider 来对外共享的
Uri
CallLog.Calls.CONTENT_URI : 等价于:Uri.parse("content://call_log/calls");
查询出所有记录
ContentResolver resolver = getContentResolver();
resolver.query(CallLog.Calls.CONTENT_URI, null, null, new String[]{"15101689022"}, null);
查询某一个联系人的所有记录(按电话号码)
resolver.query(CallLog.Calls.CONTENT_URI, null, "number=?", new String[]{"15101689022"}, null);
查询某一个联系人的所有未接电话记录(按电话号码)
resolver.query(CallLog.Calls.CONTENT_URI, null, "number=? and type=3", new String[]{"15101689022"}, null);
删除某联系人最近的一次来电
ContentResolver resolver = getContentResolver();
/* 这里涉及到内容提供者的知识,其实这里是直接在操作 Android 的数据库,十分痛苦 */
Cursor cursor = resolver.query(CallLog.Calls.CONTENT_URI, new String[]{"_id"}, "number=? and (type=1 or type=3)", new String[]{"15101689022"}, "_id desc limit 1");
if(cursor.moveToFirst()) {
int id = cursor.getInt(0);
resolver.delete(CallLog.Calls.CONTENT_URI, "_id=?", new String[] {id + ""});
}