Android 4.4设备可以充当iBeacon吗? [英] Can an Android 4.4 device act as an iBeacon?

查看:88
本文介绍了Android 4.4设备可以充当iBeacon吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在另一个问题的答案中,我看到您也可以在根植的Android 4.4上作为信标进行传输。 3台设备,但需要安装具有系统特权的应用程序。

In an answer to another question, I saw that "You can also transmit as a beacon on rooted Android 4.4.3 devices, but it requires an app installed with system privileges."

这怎么办?

推荐答案

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

Yes, this is possible on 4.4.3, but the critical API methods startAdvertising(), stopAdvertising() and getAdvScanData() (which allows you to read and write the raw information sent out in the advertisement) are blocked from use unless an app has android.permission.BLUETOOTH_PRIVILEGED. This is a system-level permission, so the only way to get this is for your custom app is to root your phone, and install your app in the /system/priv-app directory.

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

If you can accomplish that, the basic code to do this is:

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。但是您可以通过更改字节模式来传输其他信标类型。

The above code shows you how to transmit an open source AltBeacon. But you can transmit other beacon types by changing the byte pattern.

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

Another important restriction in Android 4.4 is that a bug prevents you from advertising more than 24 bytes of data, instead of the 26 that should be allowed. This means that beacon advertisements may be truncated if they require more than 24 bytes. AltBeacon, for example, uses the second of those last two bytes to store the calibrated transmitter power. Because this cannot be sent, that means distance estimates are not possible using the Android Beacon Library's standard APIs.

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

You can see a description of how this is done here

这篇关于Android 4.4设备可以充当iBeacon吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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