George Pligoropoulos
George Pligoropoulos

Reputation: 2939

How to check if an android device is equipped with a wifi adapter?

Of course the vast majority of android devices support wifi but not all of them.

How could someone check to see if the wifi is supported on the current device?
For instance with bluetooth you could just do (in Scala):

def isBluetoothSupported: Boolean = {
  BluetoothAdapter.getDefaultAdapter match {
    case null => false;
    case x: BluetoothAdapter => true;
  }
}

What is the corresponding code for wifi?

Upvotes: 4

Views: 3124

Answers (2)

ajh158
ajh158

Reputation: 1467

I don't know Scala, but the relevant API call is:

getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)

The above would allow you to detect whether wifi is available at runtime.

While not directly relevant to your question, another option that might be of use is the "uses-feature" tag element. Adding something like the following to your manifest would filter your application out on Google Play for devices without wifi:

<uses-feature android:name="android.hardware.wifi" android:required="true" />

Upvotes: 10

Nelz11
Nelz11

Reputation: 3266

You can check the system services.

if( Context.getSystemService(Context.WIFI_SERVICE) == NULL)
{
    //Service name doesn't exist
}
else
{
    //Service Exists
}

Upvotes: 1

Related Questions