Android Wifi Hotspot Manager Class

Android has the great option to let you Tether your connection via wifi, but as developer you got little to none control over this mechanism.

Therefore i wrote a class to correct this: WifiApManager.

With this class you can check the current Status of the Hotspot, enable/disable it, get/set the current AP configuration and also get the list of currently connected clients.

I also made an example to demonstrate it’s capabilities:

Here a pseudocode excerpt of the example usage:

public class Main extends Activity {
	WifiApManager wifiApManager; 
	public void onCreate(Bundle savedInstanceState) {
		wifiApManager = new WifiApManager(this);
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case 1:
			wifiApManager.setWifiApEnabled(null, true);
		case 2:
			wifiApManager.setWifiApEnabled(null, false);
Download example Sourcecode

The Code is hosted on github:

The Code is free and open source available under the Apache V2 License.

59 thoughts on “Android Wifi Hotspot Manager Class

  1. HI Nick,

    You example is very helpful. i convert it to Android Studio project and run it on my HTC phone. It created the hotspot successfull because I can found the SSID, which I set in code, on another phone.

    But my problem is when I list clients in hotspot, I got “false” value in the isReachable filed. What is the root cause for this observation?

  2. Hi Nick. First of all, thanks a ton for this wonderful example. It worked perfectly. I wanted to know whether can i get notified if any client gets connected to the hotspot. I want this to happen in the background when the app is not running. Any help to achieve this will be highly appreciated.

  3. Hi there i have implemented this into my application which runs perfectly, however after i updated to Lolipop there seems to be an issue with turning on the Access Point. I was wandering what could be the issue?

    • I had a similar issue. It seems that you need to add a new permission in the manifiest file.
      Try adding the “android.permission.CHANGE_NETWORK_STATE” permission

  4. Hey its me i have used your code in conjunction with a project someone else has worked on, however im not able to see the list of clients that have joined.

    This is the code that i have used, ignore the issue that i have asked on stack overflow i have fixed that problem now. However as mentioned before when i install the apk everything works fine however when i click the get clients button nothing seems to happen. If you would like i can give you the APK file for you to take a look?

  5. Hi, Nick
    I have more question.
    When I get a list of clients connected, client’s reachable value always ‘false’.
    And client is disconnected but list contain it’s info.
    I think it can’t be helped because arp is not refresh..
    Then, can I know connected client’s name (ex. Choi’s PC)?
    Please advice would be appreciated.

  6. Hi, Nick.
    Thanks for great library!
    I have one question.
    How can I detect client’s connection to my hotspot (after turns on the hotspot)
    like status bar-push message (ex.”1 device connected”)
    I wanna do something by programmatically when client connect hotspot.
    If you know about it, help me please.

  7. Hello i absolutely love what you have done here. Im not to sure on the regulations on the re usability of code, however would be possible if i can use this code for my dissertation project? im sorry if this is a silly question because in all i really wouldnt want to use this without your consent

    Thank you

  8. Hi. My Asus Fonepad (Android 4.4.2) has a hotspot setting that disables Wi-Fi after 8 minutes of inactivity. Is there a way to programmatically set it to never?

  9. Hi Nick,
    Firstly thanks for this excellent library.
    have you ever seen a case where android stops updating the file in proc/net/arp?

    I can connect clients to my phone’s hot stop but the file contains no listings, hence the method of reading to file to detect clients no longer works. Any ideas appreciated.

  10. Im having some problems yo open hotspot with hidden ssid by code, is this posible? Im thinking in that solution because o couldn’t connect to a password secury wifi. Any information about this?

    Thank you very much in advance!

      • Sorry about my last post, i wrote it on my cell phone and didnt checked it after writing. Im trying to open a hotspot with hiddenSSID set to true, but i can see it from all devices. Is the atribute deprecated? I have to set something else?

        WifiManagermWifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
        WifiConfiguration wifiConfig = new WifiConfiguration();
        wifiConfig.SSID = “NETWORK”;
        wifiConfig.status = WifiConfiguration.Status.ENABLED;
        Method method = mWifiManager.getClass().getMethod(“setWifiApEnabled”, WifiConfiguration.class, boolean.class);
        return (Boolean) method.invoke(mWifiManager, wifiConfig, enabled);

  11. when I disconnect client, the example can’t update the clients list in the view. And I restart the app, it can’t know the client has been disconnected either, how to know client was disconnected dynamitially?

  12. Is it possible to control access to internet after creating wifi hotspot. (like disabling internet access but keeping the wifi on)

  13. Hey, great class. Do you think there is a way to view the montly per-client data usage? I’d like o have some more detailed stats than what Android provides.

    • private void configWifi(){
      wc.SSID = “\”SSIDName\””;
      wc.preSharedKey = “password”;
      wc.hiddenSSID = true;
      wc.status = WifiConfiguration.Status.ENABLED;

  14. I want to define a connection to my access point. I want receive notifications when users connected. I know that I can query arp table(/proc/net/arp) , from which I can find connected users.
    Is there any better way to do this, except viewing arp-table every n seconds?

    • Well you could start a seperate Thread that calls an event listener instance. Inside this thread you would poll. This would not solve your problem at all but hides it 😉

  15. Hello.

    i used the above method to turn on tethering. But my AP is not found by other wifi devices. I am setting an odroid-A device as hotspot. Other wifi mobiles doesnot detect the hotspot.

    What could be the reason

  16. Hi, first of all thank you it’s very useful!
    But, do you know which broadcast intent is necessary for broadcast receivers which should listen on changes made on the device’s AP (enabling, disabling,…) ?

    thx & regards

  17. Thank, Good Information.

    if use ClientList than Use ‘Flags’ in ‘/proc/net/arp’ file.

    it can check connected or not connected~

    • Thanks for your interesting idea, could you implement it and make a pull request on github? If that’s too complicated for you, could you just send me a code example?

      Best Regards

  18. Hi Nick, great job.
    Do you know if it is possible to change the channel also?
    By default is 6, but I want to change it. I was looking in the source and I discover one field which could be suitable for that but I didn’t get anything (no change, no error)
    I’m doing this:
    WifiConfiguration netConfig = new WifiConfiguration();

    Field wcAdhocFreq = WifiConfiguration.class.getField(“frequency”);
    wcAdhocFreq.setInt(netConfig, 2462); //2462 = center freq of channel 11

    mWifiApManager.setWifiApEnabled(netConfig, true);

    any idea? thx!

  19. Hey, I found this by Google and I must say it’s so helpful, thank you for sharing :) I’ve literally just plugged this into my app (made your example app a library in eclipse) and it works like an ace, but I’m wondering if it’s possible to get the IP address of the hotspot? Can I get that from the WifiManager object? Also, do you have any specific license you want to put this under or is it free?

  20. can you tell me why is the getWifiApConfiguration() function return null and also it does not set the WifiConfiguration options when passed in setWifiApEnabled() it just uses the default Ap options.

    • Could you tell me the android version you are using? Best case you could provide me a version of the emulator to reproduce the (potential) bug?

Leave a Reply

Your email address will not be published. Required fields are marked *