Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change device name in wifidirect on android

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"?

like image 616
paulmcg Avatar asked Mar 25 '14 23:03

paulmcg


1 Answers

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) {
            }
    });
like image 196
unrealsoul007 Avatar answered Sep 21 '22 06:09

unrealsoul007