gpt4 book ai didi

android - 如何仅显示通话记录android中的未接来电

转载 作者:行者123 更新时间:2023-11-30 00:19:45 24 4
gpt4 key购买 nike

请指导我如何将条件应用于仅添加到列表中的未接来电号码的调用类型。其次热按日期排序此列表以及如何从列表中删除选定的项目。

公共(public)无效 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);
}

}

最佳答案

用下面的代码替换你的条件语句

    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";
sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration);
sb.append("\n----------------------------------");
miss_cal.setText(sb);
break;

case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}

您的代码的问题是您正在使用变量“type”测试条件 这是您的列名而不是列值。您应该已经检查了 callType,因为您还获得了调用类型。将 callType String 转换为 in,然后在与 CallLog.Calls.MISSED_TYPE 进行比较时进行转换: 希望对您有所帮助。

关于android - 如何仅显示通话记录android中的未接来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46542582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com