获取手机通话记录流程:
1、 获取ContentResolver;
ContentResolver resolver = getContentResolver();
2、resolver.query(*);
需要传入通话记录的URI:CallLog.Calls.CONTENT_URI
3、对查询得到的Cursor进行数据获取.
主要代码如下:
MainActivity.java
package com.noonecode.contentresolvercalllogdemo;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
private ListView mLvShow;
private List<Map<String, String>> dataList;
private SimpleAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLvShow = (ListView) findViewById(R.id.lv_show);
dataList = getDataList();
adapter = new SimpleAdapter(this, dataList, R.layout.simple_calllog_item//
, new String[] { "name", "number", "date", "duration", "type" }//
, new int[] { R.id.tv_name, R.id.tv_number, R.id.tv_date, R.id.tv_dura