Android WiFi Direct device details

孤街浪徒 提交于 2019-12-10 17:23:18

问题


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:


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


来源:https://stackoverflow.com/questions/10627115/android-wifi-direct-device-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!