How can i check my android device support wifi direct?

无人久伴 提交于 2019-12-02 21:29:04
StoneLam

you should check in this way, because some devices do not support WiFi direct but still keep the WifiP2pManager code in framework.

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. The latter takes an ActionListener with an onFailure() callback. The failure reason passed to onFailure(int reason) can be P2P_UNSUPPORTED, which would answer your question: the device doesn't support WiFi Direct.

A call to onSuccess() would mean the device does support WiFi Direct. A call to onFailure() with other failure reasons would probably be inconclusive as to the device's capabilities.

Shaw

Android 4.0 and later support Wi-Fi Direct. However, some of 4.x devices does not support Wi-Fi Direct because of it's WiFi driver

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. Otherwise, onFailure will be called.

Checking if Wifi P2P is supported:

  • 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)

As per your second question: yes, devices connected via wifi direct communicate without any existing wifi network.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!