Отключение точки доступа

Добрый день!

Есть метод для создания точки доступа:
public void createWifiAccessPoint() throws SocketException {
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }
        Log.d("Debug:getClass:", wifiManager.getClass().toString());
        Method[] wmMethods = wifiManager.getClass().getDeclaredMethods();
        boolean methodFound = false;
        for (Method method : wmMethods) {
            if (method.getName().equals("setWifiApEnabled")) {
                methodFound = true;
                WifiConfiguration netConfig = new WifiConfiguration();
                netConfig.SSID = name_ap;


                netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

                netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
                netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
                netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
                netConfig.preSharedKey = key;
                try {
                    boolean apstatus = (Boolean) method.invoke(wifiManager, netConfig, true);
                    for (Method isWifiApEnabledmethod : wmMethods) {
                        if (isWifiApEnabledmethod.getName().equals("isWifiApEnabled")) {
                            while (!(Boolean) isWifiApEnabledmethod.invoke(wifiManager)) {
                            }
                            for (Method method1 : wmMethods) {
                                if (method1.getName().equals("getWifiApState")) {
                                    int apstate;
                                    apstate = (Integer) method1.invoke(wifiManager);
                                    Log.d("Debug:my", String.valueOf(apstate));
                                }
                            }
                        }
                    }
                    if (apstatus) {
                        Log.d("Debug:my", "Access Point created");
                    } else {
                        Log.d("Debug:my", "Access Point creation failed");
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
        if (!methodFound) {
            Log.d("Debug:my", "cannot configure an access point");
        }
    }


То есть используется через reflection метод setWifiApEnabled класса WifiManager.
Вопрос в том, а как выключить точку доступа??
  • Вопрос задан
  • 2897 просмотров
Решения вопроса 1
@zvorygin
for (Method method : wmMethods)
  if (method.getName().equals("setWifiApEnabled"))
    method.invoke(wifiManager, netConfig, false);


Пробовали? Ну, или null вместо netConfig?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы