查看电话记录---CallLog.Calls.CONTENT_URI

来源:互联网 发布:个人网站用什么域名 编辑:程序博客网 时间:2024/04/26 05:09

查看电话记录---CallLog.Calls.CONTENT_URI 

CallLog.Calls.CACHED_NAME查询的联系人名字

CallLog.Calls.TYPE电话类型,

CallLog.Calls.NUMBER电话号码

CallLog.Calls.DATE电话日期

(注意:CallLog.Calls.TYPE电话类型的取值 来电:1,拨出:2,未接:3

 CallLog.Calls.DATE日期返回时毫秒值要处理

 

SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd "

             + "hh:mm:ss");

      Date dates = new Date(Long.parseLong(date));

      String time=simple.format(dates);

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

for (int i = 0; i < cursor.getCount(); i++) {  

  cursor.moveToPosition(i);  

//注意,如果数据表里面有一个字段:type,查询的时候,若没有设置要查type,那么在cursor里面读type的数据时候就会出现找不到列:type  

//读取数据可以理解是从cursor里面读的,当初你没查type这个字段,查询结果里面没有type的数据,当然cursor里面也就没有了  

  if(cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME))== null){  

   item.add("联系人列表无此记录");  

  }else{  

   item.add(cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME)));  

  }       

  item_2.add(cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.NUMBER)));  

 } 

 

或者

          ContentResolver cr = getContentResolver();

          String[] projects = new String[] { CallLog.Calls.NUMBER,

                     CallLog.Calls.CACHED_NAME, CallLog.Calls.TYPE,

                     CallLog.Calls.DATE };

          cursor = cr.query(CallLog.Calls.CONTENT_URI, projects, null, null,

                     CallLog.Calls.DEFAULT_SORT_ORDER);

          List<Map<String, String>> list = new ArrayList<Map<String, String>>();

          while (cursor.moveToNext()) {

                Map<String, String> map = new HashMap<String, String>();

                map.put("num", "Phone: " + cursor.getString(0));

                if (cursor.getString(1) == null) {

                     map.put("name", "");

                } else {

                     map.put("name", cursor.getString(1));

                }

                map.put("date", alterDate(cursor.getString(3)));

         ursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.DATE))

                if (cursor.getString(2).equals("1")) {             

                     map.put("state","");

                     list.add(map);

                }

          }