Domanda

When I discover peers to connect to, i can fetch the list in this method:

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

}

WifiP2PDevice.deviceName returns the name set in the System Wifi settings on the WifiDirect page.

Lets say a user sets their nickname in my app to "John", is it possible to change the device name so when another device discovers it, the name will show up as "John"?

È stato utile?

Soluzione

It uses 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) {
            }
    });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top