Android WiFi Direct device details

2019-06-24 14:47发布

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.

1条回答
Fickle 薄情
2楼-- · 2019-06-24 15:24

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();
}
查看更多
登录 后发表回答