HI i am connecting to a mobile wifi hotspot AP. How can find that connected wifi network is mobile hotspot are not?Could you please help me out from this. Thanks in advance.
Asked
Active
Viewed 166 times
2 Answers
3
You can use ConnectivityManagerCompat.isActiveNetworkMetered()
, from the support library. Check this answer for more information.
It will return true both for mobile data connections and wifi networks that correspond to mobile APs.
-
This is hardly a general solution - it only appears to work if the hotspot "sends DHCP Option 43 (Vendor specific options) with the value ANDROID_METERED" which would primarily be the case for a *phone* acting as a hotspot, but presumably not for a stand-alone hotspot device. – Chris Stratton Nov 04 '14 at 18:43
-
@ChrisStratton Yes, more or less. It will return true whenever the network is marked in Android's Mobile Hotspots preferences. While Android hotspots are marked automatically, the user toggle this for any AP if he so chooses. – matiash Nov 04 '14 at 18:46
0
One other potential option would be to make a call to a remote endpoint such as a webserver, determine the external IP address, then lookup to see if that IP address is in a range of known cellular carrier subnets. This is probably the highest accuracy solution I can think of, but of course requires much more infrastructure to work.

Jeffrey Mixon
- 12,846
- 4
- 32
- 55