简体   繁体   English

Android WiFi Direct设备详细信息

[英]Android WiFi Direct device details

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). 我想知道如何更改Android设备的WiFi Direct接口的设备详细信息(例如接口名称)。 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... :)). 我正在开发一个使用蓝牙或WiFi Direct技术进行无线通信的应用程序,它只连接到具有特定前缀的设备,以区分运行我的应用程序的设备,相对于那些只有接口的设备(我知道这是一个天真的解决方案...... :))。 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. 蓝牙允许通过使用BluetoothAdapter类提供的setName(String name)getName()方法来操作接口的setName(String name) ,但我相信不存在与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? 如果不可能,我如何区分运行我的应用程序的那些WiFi Direct设备,哪些只有那些只有接口的设备? Any help is appreciated. 任何帮助表示赞赏。 Thank you. 谢谢。

The Wi-Fi direct Name is the device name, you can change it by the following way: Wi-Fi直接名称是设备名称,您可以通过以下方式更改它:

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM