gpt4 book ai didi

两个日期之间的 Android 通话记录数据和来自同一号码的通话总时长。

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:47 27 4
gpt4 key购买 nike

想要获取今天、昨天、过去 7 天和过去 30 天的通话记录历史记录,同时我想显示该特定号码的来电和去电的总持续时间。

假设 abc 有 3 个去电和 1 个来电。我应该得到这些电话的总持续时间。

如果我们可以通过游标 GroupByORDER BY 子句而不是循环和添加持续时间来获取持续时间和调用日志,请告诉我。给我粗略的结构以获得更好的解决方案并且可以有效地工作。

         String[] whereValue=null;
Calendar calendar = Calendar.getInstance();
String currentDate = String.valueOf(calendar.getTimeInMillis());
switch (period) {
case DAY:
whereValue = new String[]{getTimeFrom(period),currentDate};
break;
case YESTERDAY:
whereValue = new String[]{getTimeFrom(period),currentDate};
break;
case WEEK:
whereValue = new String[]{getTimeFrom(period),currentDate};

break;
case MONTH:
whereValue = new String[]{getTimeFrom(period),currentDate};
break;
default:
Log.d(Utils.LOG_TAG, "Error:");
}
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Uri callUri = Uri.parse("content://call_log/calls");

Cursor cur = context.getContentResolver().query(callUri, null, android.provider.CallLog.Calls.DATE+" BETWEEN ? AND ?", whereValue, strOrder);

String callNumber = cur.getString(cur
.getColumnIndex(android.provider.CallLog.Calls.NUMBER));

String callName = cur
.getString(cur
.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
String callType = cur.getString(cur
.getColumnIndex(android.provider.CallLog.Calls.TYPE));
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
case CallLog.Calls.INCOMING_TYPE:
break;

}
String duration = cur.getString(cur
.getColumnIndex(android.provider.CallLog.Calls.DURATION));

以上代码甚至无法获取从日期到日期之间的通话记录。有帮助吗?

最佳答案

我已经设法获取了两个日期之间的通话记录。您可以获得今天、昨天、过去 7 天、过去 30 天的通话记录。以及通话时长(也有多次来自同一号码的电话)

你应该通过选择作为
android.provider.CallLog.Calls.DATE + "BETWEEN ? AND ?"

选择参数

whereValue = new String[]{String.valueOf(calendar1.getTimeInMillis()),String.valueOf(calendar.getTimeInMillis());};

  Map<String, StatEntry> callLogMap1 = new HashMap<>();
callLogMap1.clear();

String strOrder1 = android.provider.CallLog.Calls.DATE + " DESC limit 500";

Uri callUri = Uri.parse("content://call_log/calls");
Cursor cur = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, android.provider.CallLog.Calls.DATE + " BETWEEN ? AND ?", whereValue,
strOrder1);


if (cur != null) {
try {
while (cur.moveToNext()) {

String callNumber = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
// String callDate = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.DATE));
int duration = cur.getInt(cur.getColumnIndex(android.provider.CallLog.Calls.DURATION));

String name = cur.getString(cur.getColumnIndex(CallLog.Calls.CACHED_NAME));

StatEntry StatEntry1 = null;

int id = cur.getInt(cur.getColumnIndex(CallLog.Calls._ID));

int type = cur.getInt(cur.getColumnIndex(CallLog.Calls.TYPE));

if (callNumber != null & duration > 0 && (type == 1 || type == 2)) {

int n = callNumber.length();
String lastDigits;
String number = callNumber.replaceAll(Pattern.quote("+"), ""); //replacing the plus
//am just checking last 5digitis and saving to map so that we can get same //number duration
if (n >= 5) {

try {

lastDigits = String.valueOf(Long.parseLong(number) % 100000);
} catch (NumberFormatException e) {
e.printStackTrace();
lastDigits = callNumber;
}
} else {
lastDigits = callNumber;
}

if (callLogMap1.containsKey(lastDigits)) {
StatEntry1 = callLogMap1.get(callNumber);

StatEntry1.setTitle(callNumber);
StatEntry1.Duration += duration;


} else {
StatEntry1 = new StatEntry();

StatEntry1.setTitle(callNumber);

StatEntry1.Duration += duration;
}


StatEntry1.setTime((StatEntry1.Duration) / 60);


callLogMap1.put(callNumber, StatEntry1);


}
}

} catch (Exception e) {
e.printStackTrace(

);
} finally {
cur.close();
}
}

最后将 hashmap 数据传递给 arraylist。

ArrayList<StatEntry> callLogList1 = new ArrayList<>(callLogMap1.size());

if (callLogMap1.size() > 0) {
for (Map.Entry<String, StatEntry> entry : callLogMap1.entrySet()) {
callLogList1.add(entry.getValue());


}
}

希望这对观众有所帮助。

关于两个日期之间的 Android 通话记录数据和来自同一号码的通话总时长。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35207716/

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