支持WiFi直接命名的Android设备的名称 [英] Android rename device's name for wifi-direct
本文介绍了支持WiFi直接命名的Android设备的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试连接使用WiFi直接的两个设备,但我想实现编程不是由用户启动。
I am trying to connect two devices using Wifi Direct, but i want to implement programmatically not by user initiated.
和的,我要改变设备的WifiDirect的名称,比如下图:
And for that i have to change Device's WifiDirect's name like below picture :
现在发现用以下方法同龄人:
Now discover peers using following methods :
wifiP2pManager.discoverPeers(channel,
new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
Log.d(TAG, "onSuccess");
}
@Override
public void onFailure(int reason) {
Log.d(TAG, "onFailure");
}
});
通过以下code连接到特定的同行:
Connect to particular peer via following code :
public static void connectPeer(WifiP2pDevice device,
WifiP2pManager manager, Channel channel, final Handler handler) {
WifiP2pConfig config = new WifiP2pConfig();
config.groupOwnerIntent = 15;
config.deviceAddress = device.deviceAddress;
config.wps.setup = WpsInfo.PBC;
manager.connect(channel, config, new ActionListener() {
@Override
public void onSuccess() {
}
@Override
public void onFailure(int reason) {
}
});
}
但我不知道如何更改设备名称为Wi-Fi Direct的?
But i dont know how to change device name for Wi-Fi Direct?
推荐答案
这是为我工作,即使我不推荐使用反射来访问隐藏的API在WifiP2pManager。
this is what worked for me, even though I don't recommend using reflection to access hidden APIs in the WifiP2pManager.
public void setDeviceName(String devName) {
try {
Class[] paramTypes = new Class[3];
paramTypes[0] = Channel.class;
paramTypes[1] = String.class;
paramTypes[2] = ActionListener.class;
Method setDeviceName = manager.getClass().getMethod(
"setDeviceName", paramTypes);
setDeviceName.setAccessible(true);
Object arglist[] = new Object[3];
arglist[0] = channel;
arglist[1] = devName;
arglist[2] = new ActionListener() {
@Override
public void onSuccess() {
LOG.debug("setDeviceName succeeded");
}
@Override
public void onFailure(int reason) {
LOG.debug("setDeviceName failed");
}
};
setDeviceName.invoke(manager, arglist);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
这篇关于支持WiFi直接命名的Android设备的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文