zoukankan      html  css  js  c++  java
  • 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"/>

  • 相关阅读:
    maven安装与配置
    git客户端安装
    linux-更改文件属性-chattr与lsattr
    乐观锁-version的使用
    Project 專業名詞
    從 kernel source code 查出 版本號碼
    Bit banging
    Push pull, open drain circuit, pull up, pull down resistor
    Current Sourcing (拉電流) and Current Sinking(灌電流)
    學習 DT device tree 以 ST 的開發板 STM32F429i-disc1 為例
  • 原文地址:https://www.cnblogs.com/xiao-xu/p/3443721.html
Copyright © 2011-2022 走看看