Can an Android 4.4 device act like an iBeacon?

In response to another question, I saw that "you can also pass as a beacon on the root devices of Android 4.4.3, but this requires an application installed with system privileges."

How can I do that?

+3
android ibeacon android-bluetooth bluetooth-lowenergy android-ibeacon
Dec 22 '15 at 9:11
source share
1 answer

Yes, this is possible in 4.4.3, but the critical API methods startAdvertising() , stopAdvertising() and getAdvScanData() (which allow you to read and write raw information sent in ads) are blocked from use if the application has android.permission.BLUETOOTH_PRIVILEGED . This is a permission at the system level, so the only way to get this for your user application is to start your phone and install the application in the / system / priv-app directory.

If you can do this, the base code for 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); 

The above code shows how to pass the open source AltBeacon. But you can pass other types of beacons by changing the byte pattern.

Another important limitation in Android 4.4 is that the error prevents you from advertising more than 24 bytes of data, not 26, which should be allowed. This means that beacon advertisements can be truncated if they require more than 24 bytes. For example, AltBeacon uses the second of these last two bytes to store the calibrated transmitter power. Since this cannot be sent, this means that distance estimates are not possible using the standard Android Beacon Library APIs.

You can see a description of how this is done here.

+4
Dec 22 '15 at 23:53
source share



All Articles