gpt4 book ai didi

android - 双卡安卓设备的通话记录

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:20 27 4
gpt4 key购买 nike

我正在使用下面的代码来获取通话记录详细信息,这对于单 SIM 卡设备来说工作得很好,但是当涉及到双 SIM 卡时就会出现问题。我正在尝试寻找从双 SIM 卡设备获取日志的解决方法。

/**
* Get All Call Logs details as JSON
*
* @param context
*/
@SuppressLint("SimpleDateFormat")
private void getInitialCallDetailsAsJSON() {
// Print dates of the current week starting on Monday
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy hh:mm aa",
Locale.getDefault());

final Uri contacts = CallLog.Calls.CONTENT_URI;
final Cursor managedCursor = getContentResolver().query(contacts, null,
null, null, null);
final int name = managedCursor
.getColumnIndex(CallLog.Calls.CACHED_NAME);
final int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
final int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
final int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
final int durationOfCall = managedCursor
.getColumnIndex(CallLog.Calls.DURATION);

final JSONObject allDetailsJsonObject = new JSONObject();
final JSONArray array = new JSONArray();

if (managedCursor != null && managedCursor.getCount() > 0) {
while (managedCursor.moveToNext()) {
String contactName = managedCursor.getString(name);
final String phoneNumber = managedCursor.getString(number);
final String callTypeIndex = managedCursor.getString(type);
final String callDate = managedCursor.getString(date);
final String callDurationSeconds = managedCursor
.getString(durationOfCall);

final int totalTime = Integer.parseInt(callDurationSeconds);
int day = (int) TimeUnit.SECONDS.toDays(totalTime);
long hours = TimeUnit.SECONDS.toHours(totalTime) - (day * 24);
long minute = TimeUnit.SECONDS.toMinutes(totalTime)
- (TimeUnit.SECONDS.toHours(totalTime) * 60);
long second = TimeUnit.SECONDS.toSeconds(totalTime)
- (TimeUnit.SECONDS.toMinutes(totalTime) * 60);

String callDurationFormatted = "";
if (hours < 10) {
callDurationFormatted += "0" + hours + "h ";
} else {
callDurationFormatted += hours + "h ";
}

if (minute < 10) {
callDurationFormatted += "0" + minute + "m ";
} else {
callDurationFormatted += minute + "m ";
}

if (second < 10) {
callDurationFormatted += "0" + second + "s";
} else {
callDurationFormatted += second + "s";
}

String callType = null;
final int dircode = Integer.parseInt(callTypeIndex);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
callType = CallAnalyticsConstant.OUTGOING;
break;

case CallLog.Calls.INCOMING_TYPE:
callType = CallAnalyticsConstant.INCOMING;
break;

case CallLog.Calls.MISSED_TYPE:
callType = CallAnalyticsConstant.MISSED;
break;
}

if (contactName == null || contactName.equalsIgnoreCase("")) {
contactName = "UNKNOWN";
}
}
managedCursor.close();
}

如果有人有任何想法,请帮助我获取双卡手机的通话相关详细信息。

应用程序也适用于双卡手机 - CALL LOG MONITOR

最佳答案

您可以使用“sub_id”常量值来获取有关 sim 卡的信息。

此值的完整路径 CallLog.Calls.SUB_ID = "sub_id",但不可公开使用,因此只需在 21 之前在 API 中进行硬编码。对于 >=21,您可以使用 PHONE_ACCOUNT_COMPONENT_NAME。

     /**
* The subscription ID used to place this call. This is no longer used and has been
* replaced with PHONE_ACCOUNT_COMPONENT_NAME/PHONE_ACCOUNT_ID.
* For ContactsProvider internal use only.
* <P>Type: INTEGER</P>
*
* @Deprecated
* @hide
*/
public static final String SUB_ID = "sub_id";

玩得开心:)

关于android - 双卡安卓设备的通话记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23115782/

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