gpt4 book ai didi

java - 如何设置wifi direct的接口(interface)设备名称

转载 作者:行者123 更新时间:2023-12-02 04:41:06 24 4
gpt4 key购买 nike

我对这篇文章有类似的问题 Android WiFi Direct device details但是,似乎没有从该帖子中得到任何解决方案。

是否有任何方法可以用来设置类似于bluetoohAdapter和NsdServiceInfo中的“setName()”或“setServiceName”函数的wifi-direct名称。

最佳答案

我知道现在已经晚了。但你可以试试这个。在这里,您必须将 WifiP2pManager 实例WifiP2pManager.Channel 实例 以及您要设置的自定义名称 一起传递。

这对我有用,希望对你也有帮助。

    /*
Set WifiP2p Device Name
*/
public void setDeviceName(WifiP2pManager manager, WifiP2pManager.Channel channel, String deviceName){
//set device name programatically
try {
Class[] paramTypes = new Class[3];
paramTypes[0] = WifiP2pManager.Channel.class;
paramTypes[1] = String.class;
paramTypes[2] = WifiP2pManager.ActionListener.class;
Method setDeviceName = manager.getClass().getMethod(
"setDeviceName", paramTypes);
setDeviceName.setAccessible(true);

Object arglist[] = new Object[3];
arglist[0] = channel;
arglist[1] = deviceName;
arglist[2] = new WifiP2pManager.ActionListener() {

@Override
public void onSuccess() {
}

@Override
public void onFailure(int reason) {
}
};

setDeviceName.invoke(manager, arglist);

}
catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}

关于java - 如何设置wifi direct的接口(interface)设备名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30170537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com