1
public class MainActivity extends AppCompatActivity {
WifiManager wifi;
WifiReceiver wifiReceiver;
StringBuilder sb = new StringBuilder();
TextView t ;
List<ScanResult> wifiList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifi.startScan();
t=(TextView) findViewById(R.id.text);
// t.setText("Scanning....");
}
class WifiReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
wifiList = wifi.getScanResults();
sb.append("\nNumber Of Wifi connections :"+wifiList.size()+"\n\n");
for(int i = 0; i < wifiList.size(); i++){
sb.append(new Integer(i+1).toString() + ". ");
sb.append((wifiList.get(i)).toString());
sb.append("\n\n");
}
t.setText(sb);
}
}
}
我想在列表中顯示wifi網絡。我編寫了這段代碼,但屏幕上沒有顯示任何內容。有人能指出我出錯的地方嗎?無法在Android應用程序中找到WiFi網絡
謝謝!
由於它的工作! – Ravi