I\'d like my android device to connect to a wifi hotspot.
I created a new wificonfiguration
and add it into the wifimanager
, this wificonfigu
getNetworkInfo(int) method is deprecated. You can apply something like this
ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
if (activeNetwork != null) {
// connected to the internet
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
// connected to wifi
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
// connected to the mobile network
}
} else {
// not connected to the internet
}
Also, please add this permission under AndroidManifest.xml