I have an app which updates the database whenever the phone is connected to WiFi. I have implemented a Service and BroadcastReceiver which will run the Service (it will tell me what network is in use), but the problem is I don’t know what to add in the manifest file to start BroadcastReceiver when the network state changes or when it connects to some kind of network
I have an app which updates the database whenever the phone is connected to
Share
You need
In your
receivertag.Or if you want more control over it, before registering
BroadcastReceiverset these up:WIFI_STATE_CHANGED
Broadcast
<intent-action>indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown. One extra provides this state as an int. Another extra provides the previous state, if available.STATE_CHANGE
Broadcast
<intent-action>indicating that the state of Wi-Fi connectivity has changed. One extra provides the new state in the form of a NetworkInfo object. If the new state is CONNECTED, additional extras may provide the BSSID and WifiInfo of the access point. as a StringAlso, you’ll need to specify the right permissions inside
manifesttag:To check connectivity, you can use
ConnectivityManageras it tells you what type of connection is available.