androidkotlinbroadcastreceiver

How to detect SIM state change in Android


I am trying to detect changes in SIM state (in dual sim scenario - single SIM active/inactive, both SIM active/inactive) from Broadcast receiver in Android. I googled to find solution, but they are outdated, for instance, one solution was to register broadcast receiver with android.intent.action.SIM_STATE_CHANGED, which seems no more supported.

Here is the Android Manifest that I am using:


        <receiver android:name=".SIMStateChangeReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="<What should be here???>"/>
            </intent-filter>
        </receiver>

Solution

  • What you desire should be doable using SubscriptionManager. You can use it to query active subscriptions and register a listener that will notify you about any changes.