标签:
代码:
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+="\n"; // } } catch(e){ content=e.message; } outLine(content); }
标签:
原文地址:http://www.cnblogs.com/hongdada/p/4708799.html