我知道如何获取Android Wifi扫描的
我所尝试的示例:
<List>
,但我无法找出将它们制作成列表适配器的最佳方法。我希望能够将扫描的SSID和BSSID绑定到text1和text2上。我所尝试的示例:
wifi.startScan();
// get list of the results in object format ( like an array )
List<ScanResult> results = wifi.getScanResults();`
// loop that goes through list
for (ScanResult result : results) {
Toast.makeText(this, result.SSID + " " + result.level,
Toast.LENGTH_SHORT).show();
而且:
private void fillDataFromDb() {
Cursor scanCursor = Db.fetchAllScans();
startManagingCursor(scanCursor);`
// Create an array to specify the fields we want to display in the list
// (only TITLE)
String[] from = new String[] { WifiDbAdapter.KEY_BSSID,
WifiDbAdapter.KEY_SSID };
// and an array of the fields we want to bind those fields to (in this
// case just text1)
int[] to = new int[] { R.id.text1, R.id.text2 };
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter scansdb = new SimpleCursorAdapter(this,
R.layout.scan_row, scanCursor, from, to);
setListAdapter(scansdb);
}
wifi.startScan(); // 以对象格式(类似于数组)获取结果列表 List results = wifi.getScanResults();
// 循环遍历列表
for (ScanResult result : results) {
Toast.makeText(this, result.SSID + " " + result.level,
Toast.LENGTH_SHORT).show();
- Seth Hikari