-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathWifi Scanner list
44 lines (37 loc) · 1.3 KB
/
Wifi Scanner list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// You need permissions INTERNET ACCES_WIFI_STATE CHANGE_WIFI_STATE
// Only tested on Kitkat 4.4
import java.util.List;
import android.content.Context;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.app.Activity;
// This example scans for available access points and ad hoc networks.
WifiManager wifi;
WifiScanReceiver wifiReceiver;
Activity act;
Context mC;
@Override
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
act = this.getActivity();
mC= act.getApplicationContext();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
wifiReceiver = new WifiScanReceiver();
mC.registerReceiver(wifiReceiver, intentFilter);
wifi = (WifiManager) act.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifi.startScan();
}
class WifiScanReceiver extends BroadcastReceiver {
public void onReceive(Context c, Intent intent) {
List<ScanResult> wifiScanList = wifi.getScanResults();
for (int i = 0; i < wifiScanList.size(); i++) {
String info = ((wifiScanList.get(i)).toString());
println(info+"\n");
}
}
}