当前,我正在开发基于Android 26级的WIFI扫描器应用。 现在,我根据Android官方晒黑材料(https://developer.android.com/guide/topics/connectivity/wifi-scan)使用按钮手动执行WIFI扫描任务。它可以成功工作。
但是,我想设置WIFI扫描仪间隔计时器。我在互联网上做了一些调查。有人说WIFI扫描仪间隔计时器基于硬件。您无法将其固定为一个值。因此,我只是假设,如果我的设备的WIFI间隔性能为10秒,则如何使用30秒的WIFI扫描计时器设置或编码它。
非常感谢。
公共类DroneScanningPage扩展了AppCompatActivity {
private WifiManager dronesignalManger;
private ListView scanninglistView;
private Button scanningButton;
private int size = 0 ;
private List<ScanResult> scaningresultsList;
private ArrayList<String> scanningarrayList =new ArrayList<>();
private ArrayAdapter scanningarrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dronescanningpage);
Intent intent = getIntent();
scanningButton =findViewById(R.id.scanBtn);
scanningButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scanWifi();
}
});
scanninglistView = findViewById(R.id.dronedetectorscanningList);
dronesignalManger = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (!dronesignalManger.isWifiEnabled()) {
Toast.makeText(this, "Please turn on the WiFi for Drone detection", Toast.LENGTH_LONG).show();
dronesignalManger.setWifiEnabled(true);
}
scanningarrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, scanningarrayList);
scanninglistView.setAdapter(scanningarrayAdapter);
scanWifi();
}
private void scanWifi() {
scanningarrayList.clear();
registerReceiver(dronesignalReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
dronesignalManger.startScan();
Toast.makeText(this, "Scaning the drone...", Toast.LENGTH_SHORT).show();
}
BroadcastReceiver dronesignalReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
scaningresultsList = dronesignalManger.getScanResults();
unregisterReceiver(this);
for (ScanResult scanResult : scaningresultsList) {
scanningarrayList.add(scanResult.SSID + " - " + scanResult.capabilities + " - " + scanResult.BSSID + " - " + scanResult.frequency + " - " + scanResult.level);
scanningarrayAdapter.notifyDataSetChanged();
}
}
};
}