WiFi setDeviceName 只能存储 22 个字符?

WiFi setDeviceName can only store 22 chars?

所以这是我的问题,我成功更改了设备名称,但我注意到它只能存储 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)   {}

这是我猜你正在调用的方法的源代码(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, so I don't see that there is any length limit applied there. Similarly, if we look at the alternative constructor for WifiP2pDevice (line 171 中的 public String),它接受单个 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) 时,我也没有看到任何截断发生。