Kozlov
Kozlov

Reputation: 554

Is there anyway in which I can set the SSID and passphrase of my choice in wifi direct group creation

I want to create a p2p connection between a normal android WiFi device and another android device with WiFi direct support. Am successfully able to create a group(uisng createGroup of WifiP2pManager) and using the SSID and pass phrase given by the android I am also successfully able to connect a normal WiFi device to my WiFi-direct enabled device( in which I created group using wifi direct apis). But here android gives some random WiFi SSID and pass phrase , which results in me looking at the adb logs always for SSID name and then entering in the other device.

Is there anyway in which I can set the SSID and passphrase of my choice?

Thanks Kozlov

Upvotes: 3

Views: 2667

Answers (2)

Xerusial
Xerusial

Reputation: 572

Firstly, the best way would be not to change but only retrieve the WifiP2p settings and pass them you a connecting legacy device (one that does not support WifiP2p because only there you need a passphrase) using a different channel like bluetooth or NFC. A QR code may also work.

The previous Message showed you, how to get you SSID and Passphrase. The Passphrase can't be changed, however, the SSID can. The Wifi Direct spec settles the SSID to be "DIRECT__" where xy are some random generated letters during setup. So you cant change this prefix "DIRECT" and the two letters, because both the letters and passphrase are generated in internal libraries and only a read only copy is passed back to the application.

However you can change what comes afterwards the SSID prefix using reflection API.

    private void openWifiDirectChannel(String name){
    WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    WifiP2pManager.Channel channel = manager.initialize(this, getMainLooper(), null);
    //Use reflection API to get the hidden method for setting the P2P network name
    try {
        Method m = manager.getClass().getMethod(
                "setDeviceName",
                WifiP2pManager.Channel.class, String.class, WifiP2pManager.ActionListener.class );
        m.invoke(manager, channel, name, new WifiP2pManager.ActionListener() {
            public void onSuccess() {
                //Code for Success in changing name
            }

            public void onFailure(int reason) {
                //Code to be done while name change Fails
            }
        });
    } catch (Exception e)
        e.printStackTrace();
    }

Upvotes: 0

user2139927
user2139927

Reputation: 21

requestGroupInfo() enables you to get both the SSID and passphrase, however, I don't think it's possible to adjust these (yet)..

Upvotes: 2

Related Questions