如何显示来自通话记录android的未接来电

时间:2017-10-03 10:34:45

标签: android listview android-studio

请指导我如何应用条件通话类型只有未接来电号码添加到列表中。其次是按日期排序此列表以及如何从列表中删除选择的项目。

public void getlog()

    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 name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME)

    int numberOfRows = managedCursor.getCount();
    if (numberOfRows > 0) {
        if (managedCursor.moveToFirst()) {
            do {
                    String phNumber = managedCursor.getString(number);
                    String callType = managedCursor.getString(type);
                    String callDate = managedCursor.getString(date);
                    Date callDayTime = new Date(Long.valueOf(callDate));
                    String namec = managedCursor.getString(name);

                    if (namec == null) {
                        namec = "Unknown";
                    }

                    HashMap<String, String> hm = new HashMap<String, String>();
                    hm.put("listview_title", namec);
                    hm.put("listview_number", phNumber);
                    hm.put("listview_date", String.valueOf(callDayTime));
                    hm.put("listview_image", image);
                if(type == CallLog.Calls.MISSED_TYPE){ aList.add(hm);

            }
            while (managedCursor.moveToNext());
        }
        String[] from = {"listview_image", "listview_title", "listview_number", "listview_date"};
        int[] to = {R.id.listview_image, R.id.listview_item_title, R.id.listview_item_number, R.id.listview_item_time};
        SimpleAdapter simpleAdapter = new SimpleAdapter(getBaseContext(), aList, R.layout.custmlv, from, to);
        androidListView.setAdapter(simpleAdapter);
        androidListView.setOnItemLongClickListener(this);
        managedCursor.close();
         Collections.reverse(aList);
    }

}

2 个答案:

答案 0 :(得分:1)

用以下代码替换条件语句

return

您的代码存在问题,即您正在使用变量&#39; 类型&#39;来测试条件。这是您的列名而非列值。你应该检查callType,因为你也得到了呼叫类型。将callType String转换为in,然后在与CallLog.Calls.MISSED_TYPE进行比较时进行campare:  希望对你有帮助。

答案 1 :(得分:0)

    int dircode = Integer.parseInt(callType);
    switch (dircode) 
    {
    case CallLog.Calls.OUTGOING_TYPE:
    break;
    case CallLog.Calls.INCOMING_TYPE:
    break;
    case CallLog.Calls.MISSED_TYPE:
          HashMap<String, String> hm = new HashMap<String, String>();
           hm.put("listview_title", namec);
           hm.put("listview_number", phNumber);
           hm.put("listview_date", String.valueOf(callDayTime));
           hm.put("listview_image", image);
           aList.add(hm);

            break;
     }