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

4

当然,绝大多数的Android设备都支持WiFi,但并非所有设备都支持。

某人如何检查当前设备是否支持WiFi
例如,对于蓝牙,您可以执行以下操作(使用Scala):

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

WiFi对应的代码是什么?

2个回答

10

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

getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)

上述内容可以让你在运行时检测WiFi是否可用。
虽然与你的问题不直接相关,但另一个可能有用的选项是"uses-feature" tag元素。将以下内容添加到你的清单中,将会在Google Play上过滤掉没有WiFi的设备
<uses-feature android:name="android.hardware.wifi" android:required="true" />

我的应用程序中,Wifi功能是可选的,但感谢您指出这一点!我猜 hasSystemFeature 方法是检查各种硬件的通用方法。谢谢! - George Pligoropoulos

1
您可以检查系统服务。
if( Context.getSystemService(Context.WIFI_SERVICE) == NULL)
{
    //Service name doesn't exist
}
else
{
    //Service Exists
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接