简体   繁体   English

如何检查我的 android 设备是否支持 wifi 直连?

[英]How can i check my android device support wifi direct?

I am working with android wifi direct demo application.我正在使用 android wifi 直接演示应用程序。 After installation in my device I noticed that it is not working as expected.在我的设备中安装后,我注意到它没有按预期工作。

I am confused, does my device support wifi direct or special hardware feature required for wifi direct?我很困惑,我的设备是否支持 wifi direct 或 wifi direct 所需的特殊硬件功能? My device is local walton brand and API level 16. After reading android documentation i know that Wi-Fi Direct added in API level 14 doesn't need a wireless access point.我的设备是本地 walton 品牌和 API 级别 16。阅读 android 文档后,我知道在 API 级别 14 中添加的 Wi-Fi Direct 不需要无线接入点。

My other question is if in a place where no wifi zone is created using wifi direct two or more device communicate with each other.我的另一个问题是,如果在没有使用 wifi 直连创建 wifi 区域的地方,两个或多个设备是否相互通信。 in summing my problem, i need to know if my device not support wifi direct what i do to run wifi demo.总结我的问题,我需要知道我的设备是否不支持 wifi direct 我如何运行 wifi 演示。 Thanks in advance.提前致谢。

you should check in this way, because some devices do not support WiFi direct but still keep the WifiP2pManager code in framework.您应该以这种方式检查,因为有些设备不支持 WiFi 直连,但仍将 WifiP2pManager 代码保留在框架中。

private boolean isWifiDirectSupported(Context ctx) {
    PackageManager pm = ctx.getPackageManager();
    FeatureInfo[] features = pm.getSystemAvailableFeatures();
    for (FeatureInfo info : features) {
        if (info != null && info.name != null && info.name.equalsIgnoreCase("android.hardware.wifi.direct")) {
            return true;
        }
    }
    return false;
}

In addition to StoneLam's answer , which is probably the most robust, a quicker-and-dirtier method would be to go ahead and call WifiP2pManager.discoverPeers() as you would if WiFi Direct were supported.除了StoneLam 的答案(这可能是最健壮的)之外,一种更快更脏的方法是继续调用WifiP2pManager.discoverPeers(),就像支持 WiFi Direct 一样。 The latter takes an ActionListener with an onFailure() callback.后者采用带有onFailure()回调的ActionListener The failure reason passed to onFailure(int reason) can be P2P_UNSUPPORTED , which would answer your question: the device doesn't support WiFi Direct.传递给onFailure(int reason)的失败原因可以是P2P_UNSUPPORTED ,这将回答您的问题:设备不支持 WiFi Direct。

A call to onSuccess() would mean the device does support WiFi Direct.调用onSuccess()意味着该设备确实支持 WiFi Direct。 A call to onFailure() with other failure reasons would probably be inconclusive as to the device's capabilities.以其他失败原因调用onFailure()可能对设备的功能没有定论。

Android 4.0 and later support Wi-Fi Direct. Android 4.0 及更高版本支持 Wi-Fi Direct。 However, some of 4.x devices does not support Wi-Fi Direct because of it's WiFi driver但是,部分 4.x 设备不支持 Wi-Fi Direct,因为它是 WiFi 驱动程序

you can check your device using the code below您可以使用下面的代码检查您的设备

mManager.discoverPeers(mChannel, new ActionListener() {
          @Override
          public void onSuccess() {
                //onSuccess
          }
          @Override
          public void onFailure(int reason) {
                //onFailure
          }
});

If your device support Wi-Fi Direct, onSuccess will be called after a moment.如果您的设备支持 Wi-Fi Direct,稍后将调用onSuccess Otherwise, onFailure will be called.否则,将调用onFailure

Above API 21 you can directly use isP2pSupported () from WifiManager class.在 API 21 以上,您可以直接使用 WifiManager 类中的isP2pSupported () For lower Api's you can use PackageManager class,对于较低的 Api,您可以使用 PackageManager 类,

if(getPackageManager().hasSystemFeature("android.hardware.wifi.direct"))

//Wifi direct available

Checking if Wifi P2P is supported:检查是否支持 Wifi P2P:

  • In code: If you cannot get the system service, it's not supported在代码中:如果无法获取系统服务,则不支持

    mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
  • Without code: Check whether the option is in the Settings app (Under Wifi)没有代码:检查该选项是否在设置应用程序中(在 Wifi 下)

As per your second question: yes, devices connected via wifi direct communicate without any existing wifi network.根据您的第二个问题:是的,通过 wifi 直接连接的设备在没有任何现有 wifi 网络的情况下进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM