karim_fci
karim_fci

Reputation: 1242

How can i check my android device support wifi direct?

I am working with android wifi direct demo application. 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? 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.

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. in summing my problem, i need to know if my device not support wifi direct what i do to run wifi demo. Thanks in advance.

Upvotes: 3

Views: 8210

Answers (5)

Mrudul Tora
Mrudul Tora

Reputation: 768

Above API 21 you can directly use isP2pSupported () from WifiManager class. For lower Api's you can use PackageManager class,

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

//Wifi direct available

Upvotes: 2

LarsH
LarsH

Reputation: 28004

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.

Upvotes: 2

Shaw
Shaw

Reputation: 1495

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.

Upvotes: 1

StoneLam
StoneLam

Reputation: 400

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;
}

Upvotes: 13

FD_
FD_

Reputation: 12919

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.

Upvotes: -1

Related Questions