是否可以在 android 上使用 API 级别 29+ 制作 WIFI 扫描仪?

Is it possible to make WIFI scanner on android with API level 29+?

即使授予 startScan() 函数所有权限仍然 returns 错误。所以我的问题是:有没有办法扫描 android 29 或更高的接入点?

问题在于请求用户许可。我的工作代码

-清单:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

-为了询问用户权限,我使用了 EasyPermissions:

boolean scanWifi(WifiManager wifiManagerToScan) {

    String[] perm = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.CHANGE_WIFI_STATE};

    if (EasyPermissions.hasPermissions(this, perm)) {

        registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        boolean scanStarted = wifiManagerToScan.startScan();

        if (scanStarted) {
            Toast.makeText(this, "Scanning...", Toast.LENGTH_SHORT).show();
            return true;
        } else {
           Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();
            return false;
        }

    }
    else {
        EasyPermissions.requestPermissions(this, "WE REQUIRE THESE PERMISSIONS FOR THE APP TO FUNCTION", 123, perm);
        return false;
    }
}'