0

Short question: I want to check if the Personal Hotspot functionality is turned on

I am currently building a client/server application. I would like to know if my mobile (Android for instance) has tether connection activated (personal hotspot), since my server could connect to it.

I found how to detect wifi connection thanks to this answer Unity check internet connection availability but this does not detect if I am using tether connection.

Do you know how ?

Thanks you all !

ps : I don't need to know if I have an internet connection, just tether wifi working on

Orion
  • 301
  • 3
  • 12
  • Tether/hotspot is "relay my cell signal to a wifi signal for other devices." It's not actually different than a cell connection. You can do the same thing with an ethernet and wifi connection on a laptop: broadcast a wifi signal that the laptop forwards to the ethernet connection, but the laptop *itself* is still using the ethernet. – Draco18s no longer trusts SE Jun 19 '17 at 15:36

2 Answers2

1

So you want to check if the Personal Hotspot functionality is turned on? That would only allow you to determine if other devices can use your device to connect to the internet. To do that from within an Android app on the device, you would use the WiFiManager class as shown here.

Do you want to tell if something is actually connected to the hotspot? If so, you can look at this source (specifically in the getClientList method) to check for connected clients.

You mention a server. Are you trying to run a server on a desktop / laptop computer and then connect it to the personal hotspot on the device, then have the mobile app connect to some server on the desktop? If so, there are other things you'll need to consider.

wottle
  • 13,095
  • 4
  • 27
  • 68
  • I am using Unity so I was more looking for a Unity answer, but I will do more investigation with the WifiManager Android class, maybe I could manage to find something – Orion Jun 20 '17 at 23:05
  • I just want to know if I am in a hotspot mode or note (I don't need to know about internet connexion) Yes I do an Android Client, Windows Server connexion, which is working pretty well, using wifi or hotspot. But I just would like to manage the interface to tell the user it has succedly configured a hotspot and is waiting for the server. If you need more information about the product i am doing, be please to be part of the closed alpha here : https://plus.google.com/communities/114837645136205078862 – Orion Jun 20 '17 at 23:07
  • "So you want to check if the Personal Hotspot functionality is turned on?" is exaclty what I need :) – Orion Jun 20 '17 at 23:08
0

Thanks to wottle links and help, I manage to find the solution

 public bool isWifiApEnabled()
    {
        using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"))
        {
            try
            {
                using (var wifiManager = activity.Call<AndroidJavaObject>("getSystemService", "wifi"))
                {
                    return wifiManager.Call<bool>("isWifiApEnabled");
                }
            }
            catch (System.Exception e)
            {

            }
        }
        return false;
    }
Orion
  • 301
  • 3
  • 12