set Wifi Enabled using reflection - Android android.net.wifi

Android examples for android.net.wifi:Wifi Enable

Description

set Wifi Enabled using reflection

Demo Code

import java.lang.reflect.Method;

import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;

public class Main {

  public static boolean setWifiApEnabled(WifiManager wifiManager, WifiConfiguration paramWifiConfiguration,
      boolean enable) {
    try {//  w w w  . ja  v a  2 s  .c  om
      Class<? extends WifiManager> localClass = wifiManager.getClass();
      Class<?>[] arrayOfClass = new Class[2];
      arrayOfClass[0] = WifiConfiguration.class;
      arrayOfClass[1] = Boolean.TYPE;
      Method localMethod = localClass.getMethod("setWifiApEnabled", arrayOfClass);
      WifiManager localWifiManager = wifiManager;
      Object[] arrayOfObject = new Object[2];
      arrayOfObject[0] = paramWifiConfiguration;
      arrayOfObject[1] = Boolean.valueOf(enable);
      return (Boolean) localMethod.invoke(localWifiManager, arrayOfObject);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }

}

Related Tutorials