如何改变Wi-Fi直连的P2P设备名称? [英] How change the device name in WiFi direct p2p?
本文介绍了如何改变Wi-Fi直连的P2P设备名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
难道不可能性改变直接通过code的WiFi设备名称?我试过:
Is it possibile to change the device name of WiFi direct through the code? I've tried to:
private WifiP2pDevice wDevice;
wDevice.deviceName = "newName";
不过,这显然是行不通的。
任何想法?!
But, obviously it doesn't work. Any idea?!
推荐答案
下面的Java的code使用反射API,这是不太preferrable由于缺乏效率,但是Android不提供另一种方式的话,你可以用它与魅力:
Following code use Reflection api of Java,It is less preferrable due to lack of efficiency but Android does not provide another way so, You can use it works with 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();
}
这篇关于如何改变Wi-Fi直连的P2P设备名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文