Hbuilder Get call history (Android)

Source: Internet
Author: User

Code:

Date.prototype.Format =function (FMT) {varn \ {        "m+": This. GetMonth () +1,//Month        "d+": This. GetDate (),//Day        "H +": This. GetHours ()% A==0? A: This. GetHours ()% A,//hours        "H +": This. GetHours (),"m+": This. getminutes (),//points        "s+": This. getseconds (),//seconds        "q+": Math.floor (( This. GetMonth () +3) /3),//Quarterly        "F": This. Getmilliseconds ()//milliseconds    }; if(/(y+)/. Test (FMT) FMT= Fmt.replace (regexp.$1, ( This. getFullYear () +""). substr (4-regexp.$1. length));  for(varKincho)if(NewREGEXP ("("+ K +")"). Test (FMT) FMT= Fmt.replace (regexp.$1, (regexp.$1. length = =1) ? (O[k]): (("xx"+ O[k]). substr (""+o[k])); returnFMT;} function Getcalllog () {varContent=""; Try{document.getElementById ("Output"). innerhtml=""; varCalllog = Plus.android.importClass ("Android.provider.CallLog"); varMain =plus.android.runtimeMainActivity (); varobj =Main.getcontentresolver ();    Plus.android.importClass (obj); //Enquiry    varcursor = 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); varCount =0; varArr=[]; if(Cursor.movetofirst ()) { while(Cursor.movetonext ()) {count++; //number            varNumber =cursor.getstring (Cursor.getcolumnindex (CallLog.Calls.NUMBER)); //type of Call            vartype; Switch(parseint (cursor.getstring (Cursor.getcolumnindex (CallLog.Calls.TYPE) )) { CaseCallLog.Calls.INCOMING_TYPE:type="Call in";  Break;  CaseCallLog.Calls.OUTGOING_TYPE:type="Exhale out";  Break;  CaseCallLog.Calls.MISSED_TYPE:type="not received";  Break; default: Type="Hanging off";//It's supposed to hang up. Judging by my phone type,                 Break; }//var sfd = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");varDate =NewDate (parseint (cursor.getstring (Cursor.getcolumnindexorthrow (CallLog.Calls.DATE )));//var time = Sfd.format (date);//formatting effects: For example 2010-01-08 09:10:11varTime=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 Time//var time = Sfd.format (new Date (t));//var time=new Date (t);//var time=cursor.getstring (Cursor.getcolumnindexorthrow (CallLog.Calls.DATE)); //Contact Person            varName_col =Cursor.getcolumnindexorthrow (CallLog.Calls.CACHED_NAME); varName =cursor.getstring (Name_col); //Talk time, unit: s            varDuration_col =Cursor.getcolumnindexorthrow (CallLog.Calls.DURATION); varDuration =cursor.getstring (Duration_col); varobj={}; Obj.num=count; Obj.name=name; Obj.phone=Number ; Obj.time=Time ; Obj.type=type; Obj.duration=duration>3600?NewDate (duration* +). Format ("HH:mm:ss"):NewDate (duration* +). 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<arr.length;i++) {//content+=json.stringify (Arr[i]);//content+= "\ n";//  }   }     Catch(e) {content=E.message; } outLine (content);}

Hbuilder Get call history (Android)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.