HBuilder 擷取通話記錄 (Android)

來源:互聯網
上載者:User

標籤:second   uil   sage   console   replace   code   one   通話記錄   blog   

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 //      content+=JSON.stringify(arr[i]); //      content+="\n"; //  }    }      catch(e){          content=e.message;      }           outLine(content); } 

 

HBuilder 擷取通話記錄 (Android)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.