zxcvzxcv7的专栏

云在青天水在瓶

获取通话时长
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(); 




需要添加权限:

<uses-permission android:name="android.permission.READ_CONTACTS"/>

阅读更多
文章标签: null android string
个人分类: android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

获取通话时长

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭