4

I want to get call log history by sim slot number. Like this image:

Call Details want to fetch

For that I searched many sites till I got:

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);

}

Currently getting PHONE_ACCOUNT_COMPONENT_NAME and PHONE_ACCOUNT_ID as per the android documentation but how to use it to get sim slot

Followed this links :

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

but none of them worked for me.

I got the names of both current sim in dual sim in api>21 using SubscriptionManager Class but unable to check it in call log.

Kindly suggest me better way to do that.

Community
  • 1
  • 1
Vishal Dalve
  • 324
  • 3
  • 16

1 Answers1

0

You can query the following column in the CallLog: https://developer.android.com/reference/android/provider/CallLog.Calls.html#PHONE_ACCOUNT_ID

Ensure you have the following permission set:

<uses-permission android:name="android.permission.READ_CALL_LOG" />

Then add the following Java code to get the column:

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));
Faraz
  • 643
  • 4
  • 15
  • thanks, i found that but can you please post some code or small example. – Vishal Dalve Jan 12 '17 at 05:18
  • @VishalDalve Please see the edited code - I added an example. Please upvote my answer if you found it helpful, it would mean a lot. Thank you! – Faraz Jan 12 '17 at 05:49
  • If you saw my question properly, the answer you gave is already done by myself. I want next part of my question. And I already accepted your answer. Thank you. – Vishal Dalve Jan 12 '17 at 05:55