我只是想知道如果有可能通过使用xamarin为可用的wifi连接制作listview .....如果有可能那么请帮助我在这里......一步一步。
答案 0 :(得分:1)
是的,确实如此。从xamarin论坛上获取它:https://forums.xamarin.com/discussion/27364/how-to-get-list-of-wifi-networks
using Android.Content;
using Android.Net.Wifi;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace NetworkLocation.Utility
{
public class Wifi
{
private Context context = null;
private static WifiManager wifi;
private WifiReceiver wifiReceiver;
public static List<string> WiFiNetworks;
public Wifi(Context ctx)
{
this.context = ctx;
}
public void GetWifiNetworks()
{
WiFiNetworks = new List<string>();
// Get a handle to the Wifi
wifi = (WifiManager)context.GetSystemService(Context.WifiService);
// Start a scan and register the Broadcast receiver to get the list of Wifi Networks
wifiReceiver = new WifiReceiver();
context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction));
wifi.StartScan();
}
class WifiReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
IList<ScanResult> scanwifinetworks = wifi.ScanResults;
foreach(ScanResult wifinetwork in scanwifinetworks)
{
WiFiNetworks.Add(wifinetwork.Ssid);
}
}
}
}
}