是否可以通过代码更改 WiFi direct 的设备名称?我尝试过:
private WifiP2pDevice wDevice;
wDevice.deviceName = "newName";
但是,显然这是行不通的。 有什么想法吗?!
最佳答案
以下代码使用了Java的Reflection api,由于效率低下,不太可取,但Android没有提供另一种方式,您可以使用它 charm :
try {
Method m = wpm.getClass().getMethod(
"setDeviceName",
new Class[] { WifiP2pManager.Channel.class, String.class,
WifiP2pManager.ActionListener.class });
m.invoke(WifiP2pManager wifimngr,WifiP2pManager.Channel wifichannel, new_name, new WifiP2pManager.ActionListener() {
public void onSuccess() {
//Code for Success in changing name
}
public void onFailure(int reason) {
//Code to be done while name change Fails
}
});
} catch (Exception e) {
e.printStackTrace();
}
关于android - 如何更改 WiFi direct p2p 中的设备名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24851961/