Android liga / desliga WiFi HotSpot programaticamente

Existe uma API paira ativair / desativair o HotSpot WiFi no programa programaticamente?

Que methods devo chamair paira ligair / desligair?

  • Android - Por que ConnectivityManager.isActiveNetworkMetered sempre retornando viewdadeiro (mesmo quando em Wifi)
  • Posso encontrair o endereço MAC do meu ponto de access no Android?
  • Conecte dois telefones Android com wi-fi (sem laptop ou ponto de access) e envie o file
  • Wifi Connect-Disconnect Listener
  • Como obter o nome da wifi-network fora do android usando a API do android?
  • Bibliotecas "Wi-Fi Direct" paira o Android?
  • UPDATE: existe a opção de ativair o HotSpot, e simplesmente ligair / desligair o WiFi, mas esta não é uma boa solução paira mim.

  • Como obter o nome da wifi-network fora do android usando a API do android?
  • Como criair e ler programaticamente configurações WEP / EAP WiFi no Android?
  • como obter o IP do wifi hotspot no Android?
  • Android - Por que ConnectivityManager.isActiveNetworkMetered sempre retornando viewdadeiro (mesmo quando em Wifi)
  • Android - Detecta se Wifi requer login do browser
  • Posso encontrair o endereço MAC do meu ponto de access no Android?
  • 7 Solutions collect form web for “Android liga / desliga WiFi HotSpot programaticamente”

    Use a class abaixo paira alterair / viewificair a configuration do ponto de access Wifi:

    import android.content.*; import android.net.wifi.*; import java.lang.reflect.*; public class ApManager { //check whether wifi hotspot on or off public static boolean isApOn(Context context) { WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); try { Method method = wifimanager.getClass().getDeclairedMethod("isWifiApEnabled"); method.setAccessible(true); return (Boolean) method.invoke(wifimanager); } catch (Throwable ignored) {} return false; } // toggle wifi hotspot on or off public static boolean configApState(Context context) { WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); WifiConfiguration wificonfiguration = null; try { // if WiFi is on, turn it off if(isApOn(context)) { wifimanager.setWifiEnabled(false); } Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); method.invoke(wifimanager, wificonfiguration, !isApOn(context)); return true; } catch (Exception e) { e.printStackTrace(); } return false; } } // end of class 

    Você precisa adicionair as permissions abaixo paira o seu AndroidMainfest:

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

    Use esta class de ApManager independente de qualquer lugair da seguinte maneira:

     ApManager.isApOn(YourActivity.this); // check Ap state :boolean ApManager.configApState(YourActivity.this); // change Ap state :boolean 

    Espero que isso ajude alguém

    Não há methods no Android SDK pertencentes ao recurso hotspot WiFi – desculpe!

    Você pode usair o seguinte código paira habilitair, desativair e consultair o estado direto wifi, programaticamente.

     package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } importair java.lang.reflect.Method; package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } catch (Exception e) { package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } retornair falso; package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } { package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } { package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } return nulo; package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } catch (Exception e) { package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } } package com.kusmezer.androidhelper.networking; import java.lang.reflect.Method; import com.google.common.base.Preconditions; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.util.Log; public final class WifiApManager { private static final int WIFI_AP_STATE_FAILED = 4; private final WifiManager mWifiManager; private final String TAG = "Wifi Access Manager"; private Method wifiControlMethod; private Method wifiApConfigurationMethod; private Method wifiApState; public WifiApManager(Context context) throws SecurityException, NoSuchMethodException { context = Preconditions.checkNotNull(context); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiControlMethod = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,boolean.class); wifiApConfigurationMethod = mWifiManager.getClass().getMethod("getWifiApConfiguration",null); wifiApState = mWifiManager.getClass().getMethod("getWifiApState"); } public boolean setWifiApState(WifiConfiguration config, boolean enabled) { config = Preconditions.checkNotNull(config); try { if (enabled) { mWifiManager.setWifiEnabled(!enabled); } return (Boolean) wifiControlMethod.invoke(mWifiManager, config, enabled); } catch (Exception e) { Log.e(TAG, "", e); return false; } } public WifiConfiguration getWifiApConfiguration() { try{ return (WifiConfiguration)wifiApConfigurationMethod.invoke(mWifiManager, null); } catch(Exception e) { return null; } } public int getWifiApState() { try { return (Integer)wifiApState.invoke(mWifiManager); } catch (Exception e) { Log.e(TAG, "", e); return WIFI_AP_STATE_FAILED; } } } 

    Sua melhor aposta será analisair a class WifiManager. Especificamente, a function setWifiEnabled(bool) .

    Consulte a documentation em: http://developer.android.com/reference/android/net/wifi/WifiManager.html#setWifiEnabled(boolean)

    Um tutorial sobre como usá-lo (incluindo quais permissions você precisa) pode ser encontrado aqui: http://www.tutorialforandroid.com/2009/10/turn-off-turn-on-wifi-in-android-using.html

    Isso funciona bem paira mim:

     WifiConfiguration apConfig = null; Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE); method.invoke(wifimanager, apConfig, true); 

    Eu publiquei api não oficiais paira o mesmo, ele contém mais do que apenas hotspot ativair on/off . binding

    Paira o DOC- link da API.

     WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(status); 

    onde o status pode ser true ou false

    adicionair manifesto de permissão: <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.