1

I am having some problem in my simple app. In my code I am using a deprecated code so I read this documentation and I don't know how can I get the wifi status using this function getNetworkInfo (Network network) Before my code looks like this to identify its state.

 boolean wifi = conman.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();

Can you help me with this?

In using this method getNetworkInfo (Network network) what parameter should I put in order to get the state of the wifi?

Jerielle
  • 7,144
  • 29
  • 98
  • 164
  • 1
    Possible duplicate of [how to see if wifi is connected in android](http://stackoverflow.com/questions/3841317/how-to-see-if-wifi-is-connected-in-android) – SMR Feb 12 '16 at 06:58
  • 1
    refer http://stackoverflow.com/questions/33226129/getallnetworkinfo-is-deprecated – sasikumar Feb 12 '16 at 07:04

2 Answers2

1
 public static boolean isOnline(Context mContext) {
 ConnectivityManager cm = (ConnectivityManager)   mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo mWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi != null && mWifi.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}
1

Code:

ConnectivityManager manager = getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = manager.getActiveNetworkInfo();
boolean isWifi = (netInfo.getType() == ConnectivityManager.TYPE_WIFI);
boolean isConnected = (netInfo != null && netInfo.isConnectedOrConnecting());

DONE.

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
Anish Mittal
  • 1,157
  • 12
  • 29