如何从CallLog获得3个Top编号

时间:2016-02-09 19:59:05

标签: android calllog

如何根据号码的总呼叫持续时间从CallLog获取前三个号码?

例如,给定这些来电/持续时间:

  • 0123-2323 for 3min
  • 0123-2323 for 59min
  • 3232-3210持续15分钟

0123-2323的总和为totalmin=62。对于3232-3210,它是totalmin=15

我试过这段代码:

private String getCallDetails(){
    StringBuffer sb = new StringBuffer();
    Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
    int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
    int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
    int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
    int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
    sb.append("Call Details :");
    while (managedCursor.moveToNext()){
        String phNumber = managedCursor.getString(number);
        String callType = managedCursor.getString(type);
        String callDate = managedCursor.getString(date);
        Date callDayTime = new Date(Long.valueOf(callDate));
        String callDuration = managedCursor.getString(duration);
        String dir = null;
        int dircode = Integer.parseInt(callType);
        switch (dircode) {
        case CallLog.Calls.OUTGOING_TYPE:
            dir = "OUTGOING";
            break;
        case CallLog.Calls.INCOMING_TYPE:
            dir = "INCOMING";
            break;
        case CallLog.Calls.MISSED_TYPE:
            dir = "MISSED";
            break;
        }
        sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- "
                + dir + " \nCall Date:--- " + callDayTime
                + " \nCall duration in sec :--- " + callDuration);
        sb.append("\n----------------------------------");
    }
    managedCursor.close();
    return sb.toString();
}

1 个答案:

答案 0 :(得分:2)

创建地图并对其进行排序。在呼叫持续时间的基础上获取您的联系人,并获得这样的前三名联系人。

 cc1=0;
 Map<String, Integer> sortedMapa = sortByComparator(topsmstreemap, DESC);
 for (Map.Entry<String, Integer> entry : sortedMapDeses.entrySet())
 {
 if(cc1<3) 
 {cc1++;
 }