我有一个应用程序,每当用户在特定的Wifi范围内 . 我想通知用户他在wifi区域,并可以连接到这个wifi并启动应用程序 . 这个wifi是一个开放的无线网络 .

我尝试在AndroidManifest.xml中使用静态注册的广播接收器 .

AndroidManifest.xml中

<receiver android:name=".WifiReceiver" android:enabled="true" android:exported="true">
  <intent-filter android:priority="100">
    <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
    <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
    <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
  </intent-filter>
</receiver>

WifiReceiver:

if (_wifiManager == null)
            _wifiManager = (WifiManager)context.GetSystemService(Context.WifiService);
        if (_wifiManager.IsWifiEnabled)
        {
            var results = _wifiManager.ScanResults;
            if (results.Any(x => x.Ssid == "MyWifiName"))
            {
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                    .SetSmallIcon(Resource.Drawable.ic_launcher_rounded)
                    .SetContentText("Your are in wifi zone. Start the app")
                    .SetContentTitle("My App");

                NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
                notificationManager.Notify(1,mBuilder.Build());
            }
        }

现在这只适用于我改变当前连接的网络或改变wifi状态,即打开或关闭的情况 .

确切地说,我想检测一个新的wifi(开放)网络是否可用我想检查它的名字,如果是我的wifi,我想显示通知 .

我并不倾向于使用一种使用警报的最后手段

编辑:android如何显示开放wifi网络的通知可用 . 每当android通知时,我搜索wifi是否可用的理想情况 .