WIFI Direct: createGroup with config is always failure, error

0

When I call this method createGroup(WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener), it workd.

But I want to set some config, so I call createGroup(WifiP2pManager.Channel c, WifiP2pConfig config, WifiP2pManager.ActionListener listener) , it went wrong.

here is my code:

WifiP2pConfig config = new WifiP2pConfig.Builder()
            .enablePersistentMode(true)
            .setNetworkName("DIRECT-xy-MEIZU 16s")
            .setPassphrase("wanghui123456")
            .setDeviceAddress(MacAddress.fromString("72:8E:BA:03:F1:16"))
            .setGroupOperatingBand(WifiP2pConfig.GROUP_OWNER_BAND_5GHZ)
            .build();

    Log.d(TAG, "onCreateBackgroundJob: " +  config.describeContents() + config.toString());
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    manager.createGroup(channel, config, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {
            Log.d(TAG, "onSuccess: ");
        }

        @Override
        public void onFailure(int reason) {
            Log.d(TAG, "onFailure: " + reason);
        }
    });

and i got the log is onFailure: 0

ERROR
Added in API level 14
public static final int ERROR
Passed with ActionListener#onFailure. Indicates that the operation failed due to an internal error.
Constant Value: 0 (0x00000000))

android
wifi-direct
asked on Stack Overflow Apr 15, 2021 by Wh_0336

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0