简体   繁体   中英

Gatt server device name length in Android

I'm making an Gatt server app runs on android device and it works well.

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.

However, if server ran on "Galaxy S7", client can't find the server device.

So, I checked server's device name, it was "Samsung Galaxy S7" in default. After change the name to "gal7", it worked fine.

In my test, the android gatt server allow device name length maximum 8characters.

"Nexus 5x" --> fine

"Galaxy S7" --> bad

"Nexus" --> fine

"long name device" --> bad

Is there any reason(bug or not), gatt server device name length limitation?

Your problem is that the advertise packet can be 31 bytes at most. After your remove some headers you're left with 8 for the device name (assuming you're including a service UUID in the advertiser). 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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