• HBuilder 获取通话记录 (Android)


    代码:

        Date.prototype.Format = function (fmt) {  
             var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //
            "h+": this.getHours()%12==0?12:this.getHours()%12, //小时 
            "H+": this.getHours(),
            "m+": this.getMinutes(), //
            "s+": this.getSeconds(), //
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "f": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) 
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) 
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
            
      function getCallLog() {
          var content="";
         try{
        document.getElementById("output").innerHTML="";
        var CallLog = plus.android.importClass("android.provider.CallLog");
        var main = plus.android.runtimeMainActivity();
        var obj = main.getContentResolver();
        plus.android.importClass(obj);
        //查询
        var cursor = obj.query(CallLog.Calls.CONTENT_URI, null, null, null, null);
    //  var SimpleDateFormat = plus.android.importClass("java.text.SimpleDateFormat");
    //  var Date = plus.android.importClass("java.util.Date");
    //  var Long = plus.android.importClass("java.util.Long");
        plus.android.importClass(cursor);
        var count = 0;
        var arr=[];
        if (cursor.moveToFirst()) {
            while (cursor.moveToNext()) {
                count++;
                //号码
                var number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
                //呼叫类型
                var type;
                switch (parseInt(cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE)))) {
                case CallLog.Calls.INCOMING_TYPE:
                    type = "呼入";
                    break;
                case CallLog.Calls.OUTGOING_TYPE:
                    type = "呼出";
                    break;
                case CallLog.Calls.MISSED_TYPE:
                    type = "未接";
                    break;
                default:
                    type = "挂断"; //应该是挂断.根据我手机类型判断出的
                    break;
                }
    //          var sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    var date = new Date(parseInt(cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.DATE))));
    //var time = sfd.format(date);//格式化的效果:例如2010-01-08 09:10:11
    var time=date.Format("yyyy-MM-dd HH:mm:ss:f");
    //          var sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //          var Date_Col = cursor.getColumnIndex(CallLog.Calls.DATE);
    //          var Date_Value = cursor.getString(Date_Col);
    //          console.log(Date_Value);
    //          var t = parseInt(Date_Value);
    //          console.log(t);
                //呼叫时间
    //       var time = sfd.format(new Date(t));
    //          var time=new Date(t);
    //       var time=cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.DATE));
                //联系人 
                var Name_Col = cursor.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME);
                var name = cursor.getString(Name_Col);
                //通话时间,单位:s
                var Duration_Col = cursor.getColumnIndexOrThrow(CallLog.Calls.DURATION);
                var duration = cursor.getString(Duration_Col);
             
                var obj={};
                obj.num=count;
                obj.name=name;
                obj.phone=number;
                obj.time=time;
                obj.type=type;
                obj.duration=duration>3600?new Date(duration*1000).Format("HH:mm:ss"):new Date(duration*1000).Format("mm:ss");
                arr.push(obj);
                outLine(JSON.stringify(obj));
    //        console.log(JSON.stringify(obj));
                console.log(time + " " + " name:"+name+" phone:"+number + “ type:"+type + " duration:" + duration);
                content+=str;
                 if (count > 50) {
                    break;
                }
            }
     
        }
    //  console.log(JSON.stringify(arr));
    //  console.log(arr.length);
    //  content="";
    //  for(var i=0;i<arr.length;i++){
    //      content+=JSON.stringify(arr[i]);
    //      content+="
    ";
    //  }
       }
         catch(e){
             content=e.message;
         }
         
        outLine(content);
    }
  • 相关阅读:
    数字雨-贪吃蛇
    C语言入门9-2-模块大致一览
    C语言入门9-1-分类函数
    C语言入门8-数组-基本算法
    C语言入门7-程序设计方法基础-循环结构
    C语言入门6-选择结构--f语句-switch
    C语言入门5-键盘的输入和屏幕输出
    C语言入门4-运算符和表达式
    C语言入门3-C语言概述及数据类型
    Systemd 入门教程:命令篇
  • 原文地址:https://www.cnblogs.com/hongdada/p/4708799.html
Copyright © 2020-2023  润新知