Android WiFi Direct Device Information
I would like to know how I can change the WiFi Direct device information of an Android device’s interface (for example, the name of the interface). I am developing an application using Bluetooth or WiFi Direct technology for wireless communications, and it only connects to devices with a certain prefix in order to distinguish between the devices on which my application is running and those that only have an interface (I know that this naive solution ... :)). Bluetooth allows you to control the interface name using the setName(String name)
and getName()
methods provided by the BluetoothAdapter
class, but I believe that there are no corresponding for WiFi Direct. If this is not possible, how can I distinguish between WiFi Direct devices that run my application, with respect to those that have only an interface? Any help is appreciated. Thanks.
The direct Wi-Fi name is the name of the device, you can change it as follows:
public void changeWiFiDirectName(final String newName){ Method m = null; try { m = mManager.getClass().getMethod("setDeviceName", new Class[]{mChannel.getClass(), String.class, WifiP2pManager.ActionListener.class}); } catch (NoSuchMethodException e) { e.printStackTrace(); } try { if (m != null) { m.invoke(mManager, mChannel,newName, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.d(TAG, "Name changed to "+newName); } @Override public void onFailure(int reason) { Log.d(TAG, "The name was not changed"); } }); } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); }