人生处万类,知识最为贤。这篇文章主要讲述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 = https://www.songbingjia.com/android/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)】
推荐阅读
- 一起学Google Daydream VR开发,快速入门开发基础教程一(Android端开发环境配置一)
- Android开发(《Gradle Recipes for Android》阅读笔记1.3)
- Android学习笔记 布局基础
- Android开发(《Gradle Recipes for Android》阅读笔记1.2)
- MAC下如何配置Android手机调试(将测试手机加入到Mac系统的调试列表中)
- Android 计算Bitmap大小
- 去掉Android新建项目的顶部标题
- Android实战——GreenDao3.2的使用,爱不释手
- Android学习笔记---使用TabHost实现微信底部导航栏效果