0

ねえ、AndroidCallLogから通話時間を取得したい。これは、ユーザーが通話を開始する正確な時間であり、可能であれば、通話を終了する時間です。誰かが方法を知っていますか?

ありがとう!

4

2 に答える 2

1

これが完全な解決策です(テストされていませんが)-ただのスキーム:

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());
    }
}
于 2010-11-11T05:54:16.863 に答える
0

元の質問に焦点を当てた、これは@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));
    }
}
于 2015-09-25T23:59:52.453 に答える