ibeacon android系统,Android 4.4设备可以充当iBeacon吗?

是的,这在4.4.3上是可能的,但是除非应用程序能够使用,否则关键的API方法startAdvertising(),stopAdvertising()和getAdvScanData()(允许您读取和写入广告中发送的原始信息)将被禁止使用.具有android.permission.BLUETOOTH_PRIVILEGED.这是系统级别的权限,因此获取此权限的唯一方法是针对您的自定义应用程序,即将手机挂起,然后将其安装在/ system / priv-app目录中.

如果可以做到这一点,则执行此操作的基本代码是:

byte[] advertisingBytes;

advertisingBytes = new byte[] {

(byte) 0x18, (byte) 0x01, // Radius Networks manufacturer ID

(byte) 0xbe, (byte) 0xac, // AltBeacon advertisement identifier

// 16-byte Proximity UUID follows

(byte) 0x2F, (byte) 0x23, (byte) 0x44, (byte) 0x54, (byte) 0xCF, (byte) 0x6D, (byte) 0x4a, (byte) 0x0F,

(byte) 0xAD, (byte) 0xF2, (byte) 0xF4, (byte) 0x91, (byte) 0x1B, (byte) 0xA9, (byte) 0xFF, (byte) 0xA6,

(byte) 0x00, (byte) 0x01, // major: 1

(byte) 0x00, (byte) 0x02 }; // minor: 2

BluetoothManagerbluetoothManager = (BluetoothManager) this.getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE);

BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();

BluetoothAdvScanData scanData = bluetoothAdapter.getAdvScanData();

scanData.removeManufacturerCodeAndData(0x01);

scanData.setManufacturerData((int) 0x01, advertisingBytes);

scanData.setServiceData(new byte[]{}); // clear out service data.

bluetoothAdapter.startAdvertising(advertiseCallback);

上面的代码显示了如何传输开源AltBeacon.但是您可以通过更改字节模式来传输其他信标类型.

Android 4.4中的另一个重要限制是,一个错误阻止您发布超过24个字节的数据,而不是应允许的26个字节.这意味着如果信标广告需要超过24个字节,则它们可能会被截断.例如,AltBeacon使用最后两个字节中的第二个字节来存储校准的发射机功率.由于无法发送,因此无法使用Android Beacon Library的标准API进行距离估算.

您可以看到有关此操作的说明here

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值