How to detect WiFi tethering state

前端 未结 5 2069
悲哀的现实
悲哀的现实 2020-11-30 07:29

I want to know how to detect state of WiFi tethering. I\'ve seen an article: Android 2.3 wifi hotspot API But it doesn\'t work! It returns always WIFI_AP_STATE_DISABLED = 1.

5条回答
  •  自闭症患者
    2020-11-30 07:35

    Using reflection:

    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    Method[] wmMethods = wifi.getClass().getDeclaredMethods();
    for (Method method: wmMethods) {
      if (method.getName().equals("isWifiApEnabled")) {
    
        try {
          boolean isWifiAPenabled = method.invoke(wifi);
        } catch (IllegalArgumentException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          e.printStackTrace();
      }
    }
    

    As you can see here

提交回复
热议问题