Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying a SIM card slot with PHONE_ACCOUNT_ID in Android CallLogCalls

In dual-SIM card mobiles I manage to differentiate SIM cards in the calllog using the PHONE_ACCOUNT_ID property as shown in the code below. Now I need to know what SIM card actually was use (1 or 2) to make or receive the call. PHONE_ACCOUNT_ID shows something like this 8953011201104578086F for and one SIM card and similar, but no equal to the other. This was tested in a Samsung mobile:

fun readCallLog() {
    val cursor = context.contentResolver.query(CallLog.Calls.CONTENT_URI,null, null, null, CallLog.Calls.DATE + " DESC")
    val number = cursor?.getColumnIndex(CallLog.Calls.NUMBER)
    val date = cursor?.getColumnIndex(CallLog.Calls.DATE)
    val type = cursor?.getColumnIndex(CallLog.Calls.TYPE)
    val account_id = cursor?.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID)


    val tmp : MutableList<List<String?>> = mutableListOf()

    while (cursor?.moveToNext() == true ) {
        val call_number = if (number != null) cursor.getString(number) else ""
        val call_date = if(date != null) cursor.getString(date) else ""
        val call_type = if(type != null) cursor.getInt(type).toString() else ""
        val call_account_id = if(account_id != null) cursor.getString(account_id) else ""

        tmp.add( listOf(call_number, call_date, call_type, call_account_id))
    }
}
like image 839
Wrath Avatar asked Nov 05 '25 00:11

Wrath


1 Answers

You can get information on SIM cards with SubscriptionManager.getActiveSubscriptionInfoList().

On some devices, Call.PHONE_ACCOUNT_ID equals subscriptionInfo.getSubscriptionId(), however on other devices (your case) subscriptionInfo.getIccId() is a substring of it, so you need to check both.

See also SubscriptionManager reference.

like image 89
balee Avatar answered Nov 06 '25 16:11

balee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!