I want my app to have statically broadcast receiver because i want it to detect incoming message while the app is closed.I have added in manifest like
<receiver android:name=".SMSReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
now i want it to dynamically unregister by switch. when the switch is off it showed not detect incoming SMS.How i could do this. Please help me
Since you can not change the manifest content dynamically.
You can use shared Preference to store the switch state as true or false .
Then inside the
onRecieve, get the state from the preference and then perform your action only when state is true else do not perform.