Date.prototype.Format = function (fmt) {var o = {"m+": This.getmonth () + 1,//month "d+": this. GetDate (),//day "H +": This.gethours ()%12==0?12:this.gethours ()%12,//hour "H +": this.gethours (), "M + ": this.getminutes (),///Sub" s+ ": This.getseconds (),//sec" q+ ": Math.floor ((This.getmonth () + 3)/3),//Quarter Degrees "F": This.getmilliseconds ()//milliseconds}; 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]): (("XX" + o[k]). substr (("" + O[k]).)); 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); The query 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++; Number var = cursor.getstring (Cursor.getcolumnindex (CallLog.Calls.NUMBER)); Call type var type; Switch (parseint (cursor.getstring (Cursor.getcolumnindex (CallLog.Calls.TYPE))) {Case CallLog.Calls.INCOMING_T Ype:type = "Inbound"; Break Case CallLog.Calls.OUTGOING_TYPE:type = "Exhale"; Break Case CallLog.Calls.MISSED_TYPE: Type = "Not Connected"; Break Default:type = "hanging off"; It's supposed to hang up. Break according to the type of my phone; }//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),//formatted effect: For example 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); Call times//var time = Sfd.format (new Date (t)); var time=new Date (t); var time=cursor.getstring (Cursor.getcolumnindexorthrow (CallLog.Calls.DATE)); Contact var name_col = Cursor.getcolumnindexorthrow (CallLog.Calls.CACHED_NAME); var name = cursor.getstring (Name_col); Talk time, unit: 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 >) {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 Get call history (Android)