JavaForAndroid
JavaForAndroid

Reputation: 1179

Open Wi-Fi networks - Check connection in android

You might know the open Wi-Fi networks where you have to enter a password to use the internet. These are often in an airport. If you have enabled Wi-Fi your device connects to this network. Now I would like to send data with an app. So I have to check if there is a Wi-Fi network which I can use to send the data. I guess that these open networks at the airport do not allow to send data. If there is no network the device would connect via mobile data. So how can I check if it is possible to send data via Wi-Fi?

Upvotes: 0

Views: 420

Answers (1)

Jashaszun
Jashaszun

Reputation: 9270

It seems to me like you just need to check if you have Wi-Fi, since if you have Wi-Fi, you can send data through it. You check it like this:

ConnectivityManager connManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

if (wifi.isConnected())
{
    // send your data
}

Upvotes: 1

Related Questions