After flashing my Nexus 5 to the Android 5.0 preview release hammerhead-lpx13d, the OS reports that it no longer supports Bluetooth LE advertising. If you call:
((BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter().getBluetoothLeAdvertiser()
always returns null. In addition, the new method:
((BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter().isMultipleAdvertisementSupported()
always returns false
The first method used to return a valid object on the first Android L preview release for the Nexus 5 back in June. It no longer does, after flashing the latest update.
Does anybody see otherwise?
EDIT: This has been reproduced by at least one person, who opened an issue with Google here: https://code.google.com/p/android-developer-preview/issues/detail?id=1570
This is not full a solution, but a proposed work-around posted by mattprec on Google Code. It allows you to get a BluetoothLeAdvertiser
instance by calling the private constructor rather than using the public API. Unfortunately, reports of testing on a Nexus 5 and a Nexus 7 2013 edition say that even after you get an instance you can't use the object to make advertisements come out. Also, be warned that even if you can get it to work, it might break on any minor code release of Android because it is using a non-public API.
For the record, here's the code snippet copied from that page:
private static BluetoothLeAdvertiser getAdvertiserHack(BluetoothAdapter adapter) {
try {
Class<? extends BluetoothAdapter> adapterClass = adapter.getClass();
Field advertiserField = adapterClass.getDeclaredField("sBluetoothLeAdvertiser");
advertiserField.setAccessible(true);
Object advertiser = advertiserField.get(adapter);
if (advertiser == null) {
Field bluetoothManagerServiceField = adapterClass.getDeclaredField("mManagerService");
bluetoothManagerServiceField.setAccessible(true);
Object bluetoothManagerService = bluetoothManagerServiceField.get(adapter);
Constructor<?> constructor = BluetoothLeAdvertiser.class.getDeclaredConstructor(
bluetoothManagerServiceField.getType());
constructor.setAccessible(true);
advertiser = constructor.newInstance(bluetoothManagerService);
advertiserField.set(adapter, advertiser);
}
return (BluetoothLeAdvertiser) advertiser;
} catch (Exception e) {
return null;
}
}
That said, I have confirmed that advertising is supported by the Nexus 9 tablet. See here for details: http://developer.radiusnetworks.com/2014/11/18/beacon-transmission-with-android-5.html
QuickBeacon app is working fine on Nexus 9. In app there is a Beacon Format option.@davidgyoung Could you give exact String for BeaconParser to make this library transmit in iBeacon format?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With