19

I hope title itself says what my question is...

For example, We can check the Wifi availability with PackageManager like

packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI);

Similarly is there any way to detect Mobile hotspot feature availability in Android programmatically?

Thanks.

RuntimeException
  • 1,201
  • 3
  • 14
  • 25
  • Since for switching on/off wifi-hotspot there do not exist any API calls, I don't think there is a general method/way to detect presence of hotspot... but just my guess – unrealsoul007 Aug 27 '15 at 18:25
  • The thing that I'm sure about is that there's no official API for android hotspot usage. You may find this [WifiApManger](https://github.com/nickrussler/Android-Wifi-Hotspot-Manager-Class) class useful. – Navid Eivazzadeh Sep 16 '15 at 21:16

4 Answers4

4

i went through google documentation and found that if wifi P2P is supported by device then its obvious it suports wifi hotspot

to check Wi-Fi Direct/ wifi P2P by device then check this way

PackageManager m = getPackageManager();
     if (!m.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)) {
            // This device does support wifi P2P
        }

but google says its better to check for this support in your broadcast receiver itself this way

@Override
public void onReceive(Context context, Intent intent) {
    ...
    String action = intent.getAction();
    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            // Wifi P2P is enabled
        } else {
            // Wi-Fi P2P is not enabled
        }
    }
    ...
}

check google documentation for same

Jolson Da Costa
  • 1,095
  • 1
  • 12
  • 31
1

The is maybe the first step to the solution.

See: Android Wifi Hotspot Manager Class

JuergenKie
  • 109
  • 1
  • 10
  • Thanks!!! with this class, We can enable or disable hotspot. but how to detect its availibiity? – RuntimeException Aug 25 '15 at 12:58
  • 2
    Try to enable/disable in a device that is not supported, and see if any exception is thrown. See too http://stackoverflow.com/questions/12401108/how-to-check-programmatically-if-hotspot-is-enabled-or-disabled – Douglas Nassif Roma Junior Sep 10 '15 at 13:59
0

You can check this by calling this: ConnectivityManager.isActiveNetworkMetered()

This will return current active connection in Wifi Hotspot or not .

I think its a little bit helpful for you.

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
Manoj Srivastava
  • 670
  • 5
  • 16
0

You can access this information by calling ConnectivityManager.isActiveNetworkMetered().

This will return whether the active connection is a hotspot (as defined in Data Usage -> Mobile Hotspots).

Here is a good answer on similar question!!! How to detect if a network is (configured as) a mobile hotspot on Android?

Community
  • 1
  • 1
timonvlad
  • 1,046
  • 3
  • 13
  • 31