问题
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