我希望通过SIM卡插槽号获取通话记录历史记录。喜欢这张图片:
为此我搜索了许多网站,直到我得到:
Cursor managedCursor = getActivity().managedQuery(CallLog.Calls.CONTENT_URI, null,
null, null, strOrder);
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);
int account = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
account = managedCursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_COMPONENT_NAME);//for versions above lollipop
ac_id = managedCursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID);
}
目前根据Android文档获取PHONE_ACCOUNT_COMPONENT_NAME和PHONE_ACCOUNT_ID,但如何使用它来获取SIM卡插槽
关注此链接:
Samsung android 6.0 how to get dual sim call logs with sim slot id?
Get calls from log by specific SIM
How to get carrier name from dual sim phone Android?
Programmatically retrieve IMEI number for dual SIM in android
但他们都没有为我工作。
我使用SubscriptionManager Class在api> 21中获得了双sim卡中当前sim的名称,但无法在通话记录中检查它。
请建议我更好的方法。
答案 0 :(得分:0)
您可以在CallLog中查询以下列:https://developer.android.com/reference/android/provider/CallLog.Calls.html#PHONE_ACCOUNT_ID
确保您拥有以下权限:
<uses-permission android:name="android.permission.READ_CALL_LOG" />
然后添加以下Java代码以获取列:
Uri allCalls = Uri.parse("content://call_log/calls");
Cursor c = managedQuery(allCalls, null, null, null, null);
String id = c.getString(c.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));