Is there an API to turn On/Off the WiFi HotSpot on Android programmatically?
What methods should I call to turn it On/Off?
UPDATE:There's this option to have the HotSpot enabled, and just turn On/Off the WiFi, but this is not a good solution for me.
Use the class below to change/check the
Wifi hotspot
setting:You need to add the permissions below to your AndroidMainfest:
Use this standalone ApManager class from anywhere as follows:
Hope this will help someone
Applies to Oreo+ only...
I made an app with code here on GitHub which uses reflection and DexMaker to 'get at' Oreo's tethering functionality, which is now in
ConnectionManager
, rather thanWifiManager
.The stuff in
WifiManager
is good only for a closed wifi network (which explained the Closed bit in the class names!).More explanation https://stackoverflow.com/a/49356255/772333.
I have publish unofficial api's for same, it's contains more than just hotspot turn
on/off
. linkFor API's DOC - link.
This works well for me:
For Android 8.0, there is a new API to handle Hotspots. As far as I know, the old way using reflection doesn't work anymore. Please refer to:
Android Developers https://developer.android.com/reference/android/net/wifi/WifiManager.html#startLocalOnlyHotspot(android.net.wifi.WifiManager.LocalOnlyHotspotCallback,%20android.os.Handler)
Stack Overflow
How to turn on/off wifi hotspot programmatically in Android 8.0 (Oreo)
There are no methods in the Android SDK pertaining to the WiFi hotspot feature -- sorry!