android.net.WifiManager 无法解析为变量

android.net.WifiManager cannot be resolved to a variable

我的 MainActivity 中有这个 class 来检测 Internet 连接和 wifi 扫描结果。我现在收到这个错误 "android.net.wifi.SCAN_RESULTS cannot be resolved to a type" at this

内部主要活动:

class Receiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equals(
     android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {

   } else if(intent.getAction().equals(android.net.WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { //here is the error
                 }
     }
 }

        <receiver android:name=".ConnectionBroadcast" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.net.wifi.SCAN_RESULTS" />
            </intent-filter>
        </receiver>

试试这个最适合我的:

AndroidManifest

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

BroadcastReceiver class

public class WifiReceiver extends BroadcastReceiver {

   @Override
   public void onReceive(Context context, Intent intent) {

      NetworkInfo info = 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:
            WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            String ssid = wifiInfo.getSSID();
         }
      }
   }
}

权限

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