如何检查Android设备是否配备了wifi适配器?

时间:2013-05-23 21:00:47

标签: android wifi android-wifi

当然,绝大多数的Android设备都支持wifi,但不是全部。

有人可以检查当前设备上是否支持 wifi ? 例如,使用蓝牙,你可以做(​​在Scala中):

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

wifi的相应代码是什么?

2 个答案:

答案 0 :(得分:8)

我不知道Scala,但相关的API调用是:

getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)

以上将允许您检测运行时是否可以使用wifi。

虽然与您的问题没有直接关系,但另一个可能有用的选项是"uses-feature" tag元素。对于没有wifi的设备,在您的清单中添加以下内容filter your application out on Google Play

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

答案 1 :(得分:1)

您可以查看系统服务。

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