在另一个问题的答案中,我看到“您还可以在经过root的Android 4.4.3设备上作为信标进行传输,但需要安装具有系统特权的应用程序。”
如何实现这一点?
如何实现这一点?
startAdvertising()
,stopAdvertising()
和getAdvScanData()
(允许您读写在广告中发送的原始信息)被阻止使用,除非应用程序具有android.permission.BLUETOOTH_PRIVILEGED
。这是系统级权限,因此唯一获得该权限的方式是将您的自定义应用程序root您的手机,并将其安装在/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);