所以这是我的问题,我成功地更改了设备名称,但我注意到它只能存储22个字符。这是准确的还是我弄错了?如果是,我可以通过某种方式增加该大小,还是设置?我正在使用PeerListListener
检索设备。
修改
其实我觉得我只是注意到了我的错误,我在找到对手后设置了设备名称是代码:
public void onPeersAvailable(WifiP2pDeviceList peers) {
try {
Method method = p2p.getClass().getMethod("setDeviceName",
WifiP2pManager.Channel.class, String.class, WifiP2pManager.ActionListener.class);
method.invoke(p2p, channel, var, new WifiP2pManager.ActionListener() {
public void onSuccess() {
debug_print(var);
}
public void onFailure(int reason) {
debug_print(var);
}
});
} catch (Exception e) {}
答案 0 :(得分:1)
以下是我猜您正在调用的方法的来源(this source file的第1305行):
/**
* Set p2p device name.
* @hide
* @param c is the channel created at {@link #initialize}
* @param listener for callback when group info is available. Can be null.
*/
public void setDeviceName(Channel c, String devName, ActionListener listener) {
checkChannel(c);
WifiP2pDevice d = new WifiP2pDevice();
d.deviceName = devName;
c.mAsyncChannel.sendMessage(SET_DEVICE_NAME, 0, c.putListener(listener), d);
}
deviceName
只是WifiP2pDevice
中的公开String
,所以我不会看到有任何长度限制。类似地,如果我们查看WifiP2pDevice
(line 171)的替代构造函数,它接受一个String
参数并使用匹配器模式将其拆分,我们会看到设备名称的正则表达式也并不意味着长度限制:
/** Detailed device string pattern with WFD info
* Example:
* P2P-DEVICE-FOUND 00:18:6b:de:a3:6e p2p_dev_addr=00:18:6b:de:a3:6e
* pri_dev_type=1-0050F204-1 name='DWD-300-DEA36E' config_methods=0x188
* dev_capab=0x21 group_capab=0x9
*/
private static final Pattern detailedDevicePattern = Pattern.compile(
"((?:[0-9a-f]{2}:){5}[0-9a-f]{2}) " +
"(\\d+ )?" +
"p2p_dev_addr=((?:[0-9a-f]{2}:){5}[0-9a-f]{2}) " +
"pri_dev_type=(\\d+-[0-9a-fA-F]+-\\d+) " +
"name='(.*)' " + // notice no length limit here
"config_methods=(0x[0-9a-fA-F]+) " +
"dev_capab=(0x[0-9a-fA-F]+) " +
"group_capab=(0x[0-9a-fA-F]+)" +
"( wfd_dev_info=0x([0-9a-fA-F]{12}))?"
);
当设备提供给onPeersAvailable
回调(source code)时,我也看不到任何截断。