-1

I have a pretty straightforward question: Is it possible to know whether or not an active wifi connection in Android is coming from a 3G hotspot?

Context: I have a tablet without 3G, which is connected to a 3G wifi hotspot from a phone (this can be either iPhone or an Android phone). In my application, I do want to use this tethered connection to make small web service request, but some functionality within the application (like uploading photo's and such: data intensive things) I want to restrict to non-3G tethered connections.

In some other post on SO, I saw that ip addresses from Android hotspots are always 192.168.43.x; and this seems to be the case. But isn't there some generic way to find out whether or not a wifi connection is tethered from a phone?

I tried to Google the answer, but the combination of Android check wifi 3g hotspot programmatically still only result in things like How to set up a wifi hotspot with your phone, and Android turn On/Off WiFi HotSpot programmatically, so that didn't help much.

stealthjong
  • 10,858
  • 13
  • 45
  • 84
  • It would really be difficult to decide / recognize a connection type solely on it's IP address. The 192.168.x.x series is the most commonly used series for private networks. Unless, manually changed, in my experience, they almost always are from the 192.168.x.x series. So, IMO, it can't be done based purely on the IP Address. But dig around and see if something comes up. – Siddharth Lele Mar 13 '15 at 10:06
  • @siddharthLele As you could've read in my post, an Android hotspot is not 192.168.y.x, but 192.168.43.x. With that in mind, you can differtiate between home networks and Android hotspots quite easily, since most home networks are 192.168.0.x, 192.168.1.x, or 192.168.254.x. But my question was about potential metadata being broadcasted with the wifi signal, so that also iPhone hotspots can be detected. The answer, according to your comment, seems to be 'no', which makes the question itself quite narrow (for it's a yes/no question). – stealthjong Mar 13 '15 at 11:25
  • No. What I am saying is, that detecting solely on the basis of an IP Address could potentially throw false positives. And if it relies on such, then, in my opinion, it cannot be done. To rephrase the last, that might not be an optimum solution. Something more foolproof might be a better alternative. Especially considering you need to detect both Android or iPhone hotspots. – Siddharth Lele Mar 13 '15 at 12:00

1 Answers1

-1

u can check your phone's internetconnection with this method

public boolean hasConnection()
{
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    //WIFI
    NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null && wifiNetwork.isConnected())
        return true;

    //MOBILE
    NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mobileNetwork != null && mobileNetwork.isConnected())
        return true;

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

u need to add this line to your manifest

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

to only check for a mobile connection-type - you could delete the wifi-part

user0815
  • 213
  • 2
  • 11