4

I'd like to know how I can change the device details of WiFi Direct interface of an Android device (for example the name of interface). I'm developing an application that uses Bluetooth or WiFi Direct technology for wireless communications and it connects only to devices named with a particular prefix to discriminate those devices that are running my app, respect to those that have only the interface on (I know that it is a naive solution... :)). Bluetooth permits to manipulate the name of the interface by using setName(String name) and getName() methods provided by BluetoothAdapter class, but I believe that don't exist the corresponding ones for WiFi Direct. If it's not possible, how can I discriminate those WiFi Direct devices that are running my app, respect to those that have only the interface on? Any help is appreciated. Thank you.

Toto
  • 89,455
  • 62
  • 89
  • 125
user1399641
  • 41
  • 1
  • 3
  • Perhaps you should look at this already answered question : [Get WIFI interface name on android][1] [1]: http://stackoverflow.com/questions/5980826/get-wifi-interface-name-on-android – Rémi F May 18 '12 at 12:15
  • Thank you for your response! In that question, they speak about a solution to get Wifi interface name on Android, whereas I'm searching for a solution to set Wifi Direct interface name on Android! – user1399641 May 18 '12 at 16:49
  • You might want to use some service discovery like this http://developer.android.com/training/connect-devices-wirelessly/nsd.html – vjsailappan Oct 24 '12 at 06:15

1 Answers1

0

The Wi-Fi direct Name is the device name, you can change it by the following way:

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();
}
KittMedia
  • 7,368
  • 13
  • 34
  • 38
MM Manuel
  • 375
  • 2
  • 4
  • 16