我想显示可用 Wifi 设备的列表。这是我的代码,我不明白这里有什么错误:
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifi.isWifiEnabled() == false)
{
Toast.makeText(getApplicationContext(), "wifi is disabled..making it enabled",Toast.LENGTH_LONG).show();
wifi.setWifiEnabled(true);
}
String[] str1 = null;
ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,str1);
lv.setAdapter(adapter);
WifiInfo info = wifi.getConnectionInfo();
textStatus.append("\n\nWiFi Status: " + info.toString());
boolean b=wifi.isWifiEnabled();
if(b){
wifi.setWifiEnabled(false);
Toast.makeText(getApplicationContext(), "Yes", Toast.LENGTH_SHORT).show();
enter code here
这是我的代码,我想通过编程方式专门在 Android 中获取启用 Wifi 的设备属性。我怎么能得到那个?
public void onReceive(Context c, Intent intent)
{
results = wifi.getScanResults();
size = results.size();
int i = 0;
str1 = new String[size];
for (ScanResult result : results){
str1[i] = result.SSID + " " + result.level;
i++;
}