Change device name in wifidirect to android

When I discover peers to connect, I can get a list in this method:

@Override
public void onPeersAvailable(WifiP2pDeviceList peers) {
    List<WifiP2pDevice> peersList = new ArrayList<WifiP2pDevice>(peers.getDeviceList());

}

WifiP2PDevice.deviceName returns the name specified in the system Wi-Fi settings on the WifiDirect page.

Let's say the user sets his nickname in my application to “John”, is it possible to change the name of the device so that when another device detects it, the name will be displayed as “John”?

+4
source share
1 answer

It uses a hidden method. You can change the device name using the following code

Method m = manager.getClass().getMethod("setDeviceName", new Class[]     {channel.getClass(), String.class,
                    WifiP2pManager.ActionListener.class});
        m.invoke(manager, channel, newDeviceName, new WifiP2pManager.ActionListener() {

            @Override
            public void onSuccess() {
            }
            @Override
            public void onFailure(int reason) {
            }
    });
+4
source

Source: https://habr.com/ru/post/1533435/


All Articles