使用Altbeacon库发送名称为Eddystone的信标 [英] Transmit an Eddystone Beacon with name using Altbeacon Library

查看:159
本文介绍了使用Altbeacon库发送名称为Eddystone的信标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码通过我的Android设备作为Eddystone进行传输;

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");
        }

扫描设备时无法获取beacon.getBluetoothName().是否可以添加名称.我使用.setBluetoothName("devicename")添加,但扫描时未显示.返回null.

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.

推荐答案

通常无法在信标广告中添加蓝牙名称,因为BLE广告的有限数据包大小根本没有足够的空间.

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.

Beacon上的字段对传输没有影响.仅在扫描信标时填充.扫描时,数据来自称为扫描响应的单独数据包.出于实用目的,它是只读的.

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.

可以更改出现在手机自身的扫描响应中的手机的BLE名称.但是,更改此名称不仅会影响信标传输,还会影响电话上的所有蓝牙操作.这是库的BeaconTransmitter不更改此名称的另一个原因.不过,您可以自己执行此操作,方法是在Android的BluetoothAdapter类上调用setName方法.

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.

这篇关于使用Altbeacon库发送名称为Eddystone的信标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆