Search code examples
androidandroid-dialer

How to get sim id for incoming call (Default dailer)


When app is default dialer I need a way of getting sim id (1 or 2) for incoming call (dual sim).

App is implementing InCallService.


Solution

  • It looks like you can run call.getDetails().getAccountHandle().getId(), which will return a string that is the identifier of that PhoneAccountHandle.

    Note that PhoneAccountHandle is also returned from getSimCallManager

    Here's the note from the PhoneAccountHandle doc's:

    A string that uniquely distinguishes this particular PhoneAccountHandle from all the others supported by the connection service that created it.

    A connection service must select identifiers that are stable for the lifetime of their users' relationship with their service, across many Android devices. For example, a good set of identifiers might be the email addresses with which with users registered for their accounts with a particular service. Depending on how a service chooses to operate, a bad set of identifiers might be an increasing series of integers (0, 1, 2, ...) that are generated locally on each phone and could collide with values generated on other phones or after a data wipe of a given phone. Important: A non-unique identifier could cause non-deterministic call-log backup/restore behavior.

    You can also run getPhoneAccount(phoneAccountHandlerFromAbove) to get the address() i.e. phone number of the account.

    If you want to compare it to the order of things in the system, you can retrieve the list of all PhoneAccountHandle's with getCallCapablePhoneAccounts