Reputation: 597
I need to make Android application which should send some data into my server every night. If wi-fi connection is absent application should send data when connection become avaiable automatically. Why can I get event about wi-fi availability? Should I use broadcast receiver? Please, give me an example or idea. Thank you
Upvotes: 0
Views: 173
Reputation: 16363
Register in your AndroidManifest.xml BroadcastReceiver
which checks wifi status, like:
<receiver
android:name=".receivers.WifiStatusReceiver"
android:label="NetworkChangeReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
And then implement your own BroadcastReceiver
, which will handle event when wi-fi will be available, so you can start upload/download
Upvotes: 1
Reputation: 30648
Android comes with a complete support for the WiFi connectivity. The main component is the system-provided WiFiManager. As usual, we obtain it via getSystemServices()
call to the current context.
Once we have the WiFiManager, we can ask it for the current WIFi connection in form of WiFiInfo object. We can also ask for all the currently available networks via getConfiguredNetworks()
. That gives us the list of WifiConfigurations.
// Setup WiFi
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// Get WiFi status
WifiInfo info = wifi.getConnectionInfo();
// info.toString()
// List available networks
List<WifiConfiguration> configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
// config.toString()
}
refer detailed example
Upvotes: 0