Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How change the device name in WiFi direct p2p?

Is it possibile to change the device name of WiFi direct through the code? I've tried to:

private WifiP2pDevice wDevice;
wDevice.deviceName = "newName";

But, obviously it doesn't work. Any idea?!

like image 915
user3809345 Avatar asked Jul 20 '14 15:07

user3809345


People also ask

What is peer devices in Wi-Fi Direct?

Wi-Fi Direct (also known as peer-to-peer or P2P) allows your application to quickly find and interact with nearby devices, at a range beyond the capabilities of Bluetooth. The Wi-Fi Direct (P2P) APIs allow applications to connect to nearby devices without needing to connect to a network or hotspot.

How do I enable P2P on Android?

Android P2P is now called WiFi Direct. On the Settings panel select Wi-Fi. You'll see a list of WiFi networks but you want to click the menu button on the lower right (the vertical ...). This opens up a submenu with Wi-Fi Direct as one of the options, select it.


1 Answers

Following code use Reflection api of Java,It is less preferrable due to lack of efficiency but Android does not provide another way so, You can use it works with charm :

    try {
        Method m = wpm.getClass().getMethod(
                "setDeviceName",
                new Class[] { WifiP2pManager.Channel.class, String.class,
                        WifiP2pManager.ActionListener.class });

        m.invoke(WifiP2pManager wifimngr,WifiP2pManager.Channel wifichannel, new_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();
    }
like image 139
user3409573 Avatar answered Sep 19 '22 06:09

user3409573