'Get dual sim phone call logs (Call Log Is from what Sim Card)
We're creating a call log application and in a call log I want to show the user that the call log is from sim 1 or sim 2. I found this but when I try to get it, it's null
curser.getString(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));
How can I find out the call log I get is from what sim card slot?
Solution 1:[1]
I think you have a typo
Your code:
curser.getString(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));
The "e" in "curser" should be changed to "o"
Code without typo:
cursor.getString(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));
Solution 2:[2]
For all those who are still looking for a solution, please try this code
First, you need to add <uses-permission android:name="android.permission.READ_PHONE_STATE" />
in your manifest file.
Second, you need to get the SIM Subscription Id associated with the Call Log using curser.getString(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID))
Then pass the SIM Subscription Id to this function -
fun getSimInfoSubscriptionId(id: String): Int {
var simSlotIndex = -1
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.READ_PHONE_STATE
) == PackageManager.PERMISSION_GRANTED
) {
// Get subscription id's of all active sim's
val subscriptionList = subscriptionManager.activeSubscriptionInfoList
for (subscription in subscriptionList) {
// If id is equal to the subscriptionId then assign the simSlotIndex
if (subscription.subscriptionId.toString() == id) {
simSlotIndex = subscription.simSlotIndex
break
}
}
}
}
return simSlotIndex
}
If simSlotIndex = 0
then it is SIM 1 or if simSlotIndex = 1
then it is SIM 2 :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | EMMANUEL NGENE |
Solution 2 | Aditya vikram Shekhawat |