For the IoT you can use a cheap esp8266 microcontroller with WiFi onboard. To connect the esp8266 to the wireless network you can use the following lua snippet that will work with the nodemcu..
If you want to try downloading something unless you have wifi. You can use the following code snippet to be able to check if wifi is enabled. You will be able to use the ConnectivityManager to get the state of the Wifi adapter. From there you can check if it is connected or even available. ConnectivityManager ..