当前位置: 移动技术网 > 移动技术>移动开发>Android > Android获取通话时间实例分析

Android获取通话时间实例分析

2019年07月24日  | 移动技术网移动技术  | 我要评论
本文章总结了一段android获取通话时间程序代码,有需要的朋友可参考一下。

我们知道安卓系统中通话时长应该是归callog管,所以建议去查查contactprovider,或者是telephonyprovider

service测试

可以的通话开始的时候启动service 记录当前时间a, 然后stopself(); 另外在通话结束的时候再次启动一下service,再次获得当前时间b, 然后把时间a和b进行比较处理

string time = long.tostring(比较后处理的时间)

然后调用

复制代码 代码如下:

toast.maketext(this, time, toast.length_short).show();

使之显示出来 ,再stopself();

获取联系人通话时间的长短java代码
复制代码 代码如下:

cursor cursor = getcontentresolver().query(calls.content_uri,
new string[] { calls.duration, calls.type, calls.date },
null,
null,
calls.default_sort_order);
mainactivity.this.startmanagingcursor(cursor);
boolean hasrecord = cursor.movetofirst();
long incoming = 0l;
long outgoing = 0l;
int count = 0;
while (hasrecord) {
int type = cursor.getint(cursor.getcolumnindex(calls.type));
long duration = cursor.getlong(cursor.getcolumnindex(calls.duration));
switch (type) {
case calls.incoming_type:
incoming += duration;
break;
case calls.outgoing_type:
outgoing += duration;
default:
break;
}
count++;
hasrecord = cursor.movetonext();
}
toast.maketext(mainactivity.this,
"共计 " + count + "次通话 . 总通话时长 " + (incoming + outgoing) + "秒. 其中接听 " + incoming + " 秒, 拔打 "
+ outgoing + " 秒.",
toast.length_long).show();

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网