Skip to content Skip to sidebar Skip to footer

Android.net.wifimanager Cannot Be Resolved To A Variable

I have this class in my MainActivity to detect Internet Connection and wifi scanning result. I am getting at the Moment this error 'android.net.wifi.SCAN_RESULTS cannot be resolved

Solution 1:

Just try this The best that worked for me:

AndroidManifest

<receiverandroid:name="com.AEDesign.communication.WifiReceiver" ><intent-filterandroid:priority="100"><actionandroid:name="android.net.wifi.STATE_CHANGE" /></intent-filter></receiver>

BroadcastReceiver class

publicclassWifiReceiverextendsBroadcastReceiver {

   @OverridepublicvoidonReceive(Context context, Intent intent) {

      NetworkInfoinfo= intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
      if(info != null) {
         if(info.isConnected()) {
            // Do your work. // e.g. To check the Network Name or other info:WifiManagerwifiManager= (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
            WifiInfowifiInfo= wifiManager.getConnectionInfo();
            Stringssid= wifiInfo.getSSID();
         }
      }
   }
}

Permissions

<uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE"/><uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>

Post a Comment for "Android.net.wifimanager Cannot Be Resolved To A Variable"