简体   繁体   English

Android中的Gatt服务器设备名称长度

[英]Gatt server device name length in Android

I'm making an Gatt server app runs on android device and it works well. 我正在使Gatt服务器应用程序在android设备上运行,并且效果很好。

But I have a question about device name. 但是我对设备名称有疑问。

I created this application with my "Nexus 5X", and it's default device name is "Nexus 5x" and Gatt client can scan this device well. 我使用“ Nexus 5X”创建了此应用程序,其默认设备名称为“ Nexus 5x”,Gatt客户端可以很好地扫描此设备。

However, if server ran on "Galaxy S7", client can't find the server device. 但是,如果服务器在“ Galaxy S7”上运行,则客户端找不到服务器设备。

So, I checked server's device name, it was "Samsung Galaxy S7" in default. 因此,我检查了服务器的设备名称,默认情况下为“ Samsung Galaxy S7”。 After change the name to "gal7", it worked fine. 将名称更改为“ gal7”后,它可以正常工作。

In my test, the android gatt server allow device name length maximum 8characters. 在我的测试中,android gatt服务器允许设备名称的最大长度为8个字符。

"Nexus 5x" --> fine “ Nexus 5x”->很好

"Galaxy S7" --> bad “ Galaxy S7”->不好

"Nexus" --> fine “ Nexus”->很好

"long name device" --> bad “长名称设备”->不好

Is there any reason(bug or not), gatt server device name length limitation? gatt服务器设备名称长度限制是否有任何原因(错误与否)?

Your problem is that the advertise packet can be 31 bytes at most. 您的问题是广告数据包最多可以是31个字节。 After your remove some headers you're left with 8 for the device name (assuming you're including a service UUID in the advertiser). 删除一些标头后,设备名称剩下8(假设广告客户中包含服务UUID)。 The correct way to do this if you want to include the device name in the advertisement is something like this: 如果要在广告中包括设备名称,则执行此操作的正确方法如下所示:

AdvertiseSettings mAdvertiseSettings = new AdvertiseSettings.Builder()
        .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
        .setConnectable(true)
        .setTimeout(0)
        .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
        .build();
AdvertiseData mAdvertiseData = new AdvertiseData.Builder()
        .setIncludeDeviceName(false)
        .addServiceUuid(new ParcelUuid(MY_SERVICE_UUID))
        .build();
AdvertiseData mScanResponseData = new AdvertiseData.Builder()
        .setIncludeDeviceName(true)
        .build();
BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser()
        .startAdvertising(mAdvertiseSettings, mAdvertiseData,
                mScanResponseData, this /* AdvertiseCallback */);

What this is doing is sending the UUID of your primary service with the advertise packed while keeping the Rx channel open for a scan response request which will send the name (up to 27 characters I think). 这是在发送带有打包广告的主服务的UUID时,同时保持Rx通道打开以进行扫描响应请求,该请求将发送名称(我认为最多27个字符)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM