从 Android CallLog 获取通话时间

发布于 2024-10-01 15:56:14 字数 87 浏览 3 评论 0原文

嘿,我想从 Android CallLog 中获取通话时间。这是用户开始呼叫的确切时间,如果可能的话,当他完成呼叫时。有人知道怎么做吗?

谢谢!

Hey, I want to get the hour of the calling from the Android CallLog. It is, the exactly hour that the user start the calling and if possible when he finishes the calling. Someone knows how to?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆兒滾 2024-10-08 15:56:16

这是完整的解决方案(尽管未经测试) - 只是方案:

public void logCallLog(String number)
{
    long dialed;
    String columns[]=new String[] {
            CallLog.Calls._ID, 
            CallLog.Calls.NUMBER, 
            CallLog.Calls.DATE, 
            CallLog.Calls.DURATION, 
            CallLog.Calls.TYPE};
    String args[]=new String[1];
    args[0]=number;
    Cursor c;
    c = this.managedQuery(Uri.parse("content://call_log/calls"),
            columns, CallLog.Calls.NUMBER+"=?", args, "Calls._ID DESC"); //last record first
    while (c.moveToNext())
    {
        dialed=c.getLong(c.getColumnIndex(CallLog.Calls.DATE));
        Log.i("CallLog", "Call to number: "+number+", registered at: "+new Date(dialed).toString());
    }
}

Here is complete solution (though not tested) - just scheme:

public void logCallLog(String number)
{
    long dialed;
    String columns[]=new String[] {
            CallLog.Calls._ID, 
            CallLog.Calls.NUMBER, 
            CallLog.Calls.DATE, 
            CallLog.Calls.DURATION, 
            CallLog.Calls.TYPE};
    String args[]=new String[1];
    args[0]=number;
    Cursor c;
    c = this.managedQuery(Uri.parse("content://call_log/calls"),
            columns, CallLog.Calls.NUMBER+"=?", args, "Calls._ID DESC"); //last record first
    while (c.moveToNext())
    {
        dialed=c.getLong(c.getColumnIndex(CallLog.Calls.DATE));
        Log.i("CallLog", "Call to number: "+number+", registered at: "+new Date(dialed).toString());
    }
}
故人的歌 2024-10-08 15:56:16

专注于原来的问题,这是一个基于@barmaley 的解决方案:

public void logCallLog(String number)
{
    long dialed;
    String columns[]=new String[] {
            CallLog.Calls._ID, 
            CallLog.Calls.NUMBER, 
            CallLog.Calls.DATE, 
            CallLog.Calls.DURATION, 
            CallLog.Calls.TYPE};
    String args[]=new String[1];
    args[0]=number;
    Cursor c;
    c = this.managedQuery(Uri.parse("content://call_log/calls"), columns, CallLog.Calls.NUMBER+"=?", args, "Calls._ID DESC"); //last record first
    while (c.moveToNext())
    {
        int duration = c.getInt(c.getColumnIndex(CallLog.Calls.DURATION));// for duration in seconds            
        dialed=c.getLong(c.getColumnIndex(CallLog.Calls.DATE));
        GregorianCalendar callStart = new GregorianCalendar();
        callStart.setTimeInMillis(dialed);
        int hstart = callStart.get(GregorianCalendar.HOUR_OF_DAY);

        //using callStart and duration you can calculate the end hour:
        dialed += duration+1000;
        GregorianCalendar callEnd = new GregorianCalendar();
        callEnd.setTimeInMillis(dialed);
        int hend = callEnd.get(GregorianCalendar.HOUR_OF_DAY);

        Log.i("CallLog", String.format("Start:%d End:%d", hstart, hend));
    }
}

Focused on the original question, this is a solution, based on @barmaley's:

public void logCallLog(String number)
{
    long dialed;
    String columns[]=new String[] {
            CallLog.Calls._ID, 
            CallLog.Calls.NUMBER, 
            CallLog.Calls.DATE, 
            CallLog.Calls.DURATION, 
            CallLog.Calls.TYPE};
    String args[]=new String[1];
    args[0]=number;
    Cursor c;
    c = this.managedQuery(Uri.parse("content://call_log/calls"), columns, CallLog.Calls.NUMBER+"=?", args, "Calls._ID DESC"); //last record first
    while (c.moveToNext())
    {
        int duration = c.getInt(c.getColumnIndex(CallLog.Calls.DURATION));// for duration in seconds            
        dialed=c.getLong(c.getColumnIndex(CallLog.Calls.DATE));
        GregorianCalendar callStart = new GregorianCalendar();
        callStart.setTimeInMillis(dialed);
        int hstart = callStart.get(GregorianCalendar.HOUR_OF_DAY);

        //using callStart and duration you can calculate the end hour:
        dialed += duration+1000;
        GregorianCalendar callEnd = new GregorianCalendar();
        callEnd.setTimeInMillis(dialed);
        int hend = callEnd.get(GregorianCalendar.HOUR_OF_DAY);

        Log.i("CallLog", String.format("Start:%d End:%d", hstart, hend));
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文