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?!
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With