回答

4

是的,这是可能的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中的另一个重要限制是,一个bug会阻止您发布超过24个字节的数据,而不是应该允许的26个字节。这意味着如果信标广告需要多于24个字节,则它可能会被截断。例如,AltBeacon使用最后两个字节中的第二个字节来存储校准的发射机功率。由于无法发送,因此使用Android Beacon库的标准API无法估计距离。

你可以看到如何完成的描述here

相关问题