当我在Samsung Galaxy S6 SM-G920I上测试我的应用程序时,它不起作用。 Basaclly应用程序在那里,但不显示访问点信息。
我的大多数代码都在线上获得,但是我在beginnig处修改了结果给了ssid。现在它给出了ssid bssid rssi和时间戳
代码在这里找到 https://medium.com/@ssaurel/develop-a-wifi-scanner-android-application-daa3b77feb73
private WifiManager wifiManager;
private ListView listView;
private Button buttonScan;
private int size = 0;
private List<ScanResult> results;
private ArrayList<String> arrayList = new ArrayList<>();
private ArrayAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonScan = findViewById(R.id.scanBtn);
buttonScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
scanWifi();
}
});
listView = findViewById(R.id.wifiList);
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) {
Toast.makeText(this, "WiFi is disabled ... We need to enable it", Toast.LENGTH_LONG).show();
wifiManager.setWifiEnabled(true);
}
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);
listView.setAdapter(adapter);
scanWifi();
}
private void scanWifi() {
arrayList.clear();
registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifiManager.startScan();
Toast.makeText(this, "Scanning WiFi ...", Toast.LENGTH_SHORT).show();
}
BroadcastReceiver wifiReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
results = wifiManager.getScanResults();
unregisterReceiver(this);
for (ScanResult scanResult : results) {
arrayList.add(scanResult.SSID +scanResult.level +scanResult.BSSID+scanResult.timestamp+scanResult.capabilities);
adapter.notifyDataSetChanged();
}
}
};
}
Mainfest
package="com.example.a0e2fa">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.a0e2fa.WiFiScannerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>