Transmit an Eddystone Beacon with name using Altbeacon Library

北城余情 提交于 2020-05-17 07:45:16

问题


I use the following code transmiting as Eddystone using my Android device;

 try {
            byte[] urlBytes = UrlBeaconUrlCompressor.compress("http://www.****.com");
            Identifier encodedUrlIdentifier = Identifier.fromBytes(urlBytes, 0, urlBytes.length, false);
            ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
            identifiers.add(encodedUrlIdentifier);
            Beacon beacon = new Beacon.Builder()
                    .setBluetoothName("devicename")
                    .setIdentifiers(identifiers)
                    .setManufacturer(0x0118)
                    .setTxPower(-59)
                    .build();
            BeaconParser beaconParser = new BeaconParser()
                    .setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT);
            BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
            beaconTransmitter.startAdvertising(beacon);
        } catch (MalformedURLException e) {
            Log.d("ww", "That URL cannot be parsed");
        }

I can not get beacon.getBluetoothName() when scan device. Is it possible to add name. I added using .setBluetoothName("devicename") but it is not showing when scan. It return null.


回答1:


It is generally not possible to add a Bluetooth name to a beacon advertisement, as there is simply not enough room in the limited data packet size of a BLE advertisement.

The field on the Beacon has no effect on transmissions. It is only populated when scanning for beacons. When scanning, the data comes from a separate packet called the scan response. For practical purposes it is read only.

It is possible to change a phone's BLE name that appears in the phone's own scan response. However, changing this name affects not just beacon transmissions but all Bluetooth operations on the phone. This is yet another reason that the library's BeaconTransmitter does not change this name. You can do so youself, however, by calling the setName method on Android's BluetoothAdapter class.



来源:https://stackoverflow.com/questions/61836111/transmit-an-eddystone-beacon-with-name-using-altbeacon-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!