Toggle wifi tethering programmatically in Android 4.2

后端 未结 2 2005
故里飘歌
故里飘歌 2021-02-11 08:27

Is there any possibility to toggle wifi tethering in Android 4.2? I tried this but it seems that it doesn\'t work using Android 4.2!

Thanks in advance!

Edit: It

2条回答
  •  长发绾君心
    2021-02-11 08:54

    You should be able to do it in Android 4.2 make sure you have the permission

    android.permission.CHANGE_WIFI_STATE
    

    and we cannot help you unless you post your code.

    I believe this will help you check if tethering is active

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

提交回复
热议问题