• Android获取手机通讯记录


     StringBuilder smsBuilder1 = new StringBuilder();

    String str = null;
      String strNumber,strName = "";
         int type;
         long callTime;
         Date date;
         String time= "";
         ContentResolver cr = getContentResolver();
         final Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI,
                                  new String[]{CallLog.Calls.NUMBER,CallLog.Calls.CACHED_NAME,CallLog.Calls.TYPE, CallLog.Calls.DATE,CallLog.Calls.DURATION},
                                  null, null,CallLog.Calls.DEFAULT_SORT_ORDER);
         cursor.moveToPosition(0);
         do{  
          strNumber = cursor.getString(0);    //呼叫号码
          strName = cursor.getString(1);   //联系人姓名
          type = cursor.getInt(2);  //来电:1,拨出:2,未接:3 public static final int INCOMING_TYPE = 1;   public static final int OUTGOING_TYPE = 2;   public static final int MISSED_TYPE = 3;
          if(type == 1){
           str = "来电";
          }else if(type == 2){
           str = "拨出";
          }else if(type == 3){
           str = "未接";
          }
          long duration = cursor.getLong(4);  //通话时间
          SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
          date = new Date(Long.parseLong(cursor.getString(3)));
          time = sfd.format(date);
          smsBuilder1.append(strNumber+",");
          smsBuilder1.append(strName+",");
          smsBuilder1.append(str+",");
          smsBuilder1.append(duration+",");
          smsBuilder1.append(time+" ");
            }while(cursor.moveToNext());
        
            textView2.setText(smsBuilder1.toString());

    添加权限:

    <uses-permission android:name="android.permission.CALL_PHONE"/>
        <uses-permission android:name="android.permission.READ_CALL_LOG"/>
        <uses-permission android:name="android.permission.WRITE_CALL_LOG"/>

  • 相关阅读:
    指针符号的优先级
    逆序链表建立和输出
    typedef关键字编写步骤
    CasePlayer2-嵌入式软件静态解析工具
    嵌入式软件测试工具和测试方法
    单元测试必要性
    基于winAMS、CasePlayer2嵌入式软件单元测试
    嵌入式软件测试软件--winAMS支持芯片
    基于模型开发 Back-to-Back测试统合工具-MC-Verifier
    单元测试工具-winAMS
  • 原文地址:https://www.cnblogs.com/xiao-xu/p/3443721.html
Copyright © 2020-2023  润新知