Reputation: 734
I have 2 beacons nearby, and the manufacturer indicates their UUID are all the same of:
beacon uuid: fda50693-a4e2-4fb1-afcf-c6eb07647825
by using the direct Android API, I can constantly(every seconds) see the beacon mac and scanRecord
via:
ScanCallback leScanCallback =
new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
// scanned result data bytes sample:onScanResult-> deviceName: R24110120, rssi: -52,
// deviceMacAddress: 52:0A:24:11:00:78,
//scanRecord: 0201061aff4c000215fda50693a4e24fb1afcfc6eb0764782500010002d80a0952323431313031323011160318520a24110078000100020603e864000000
}
};
var bluetoothLeScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();
var bluetoothLeScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();
ScanSettings settings = new ScanSettings.Builder().build();
ScanFilter scanFilter = new ScanFilter.Builder().build();
ArrayList<ScanFilter> scanFilters = new ArrayList<>();
scanFilters.add(scanFilter);
bluetoothLeScanner.startScan(scanFilters, settings, leScanCallback);
while if I choose the library for scanning:
beaconManager = BeaconManager.getInstanceForApplication(this);
// To detect proprietary beacons, you must add a line like below corresponding to yo
// type. Do a web search for "setBeaconLayout" to get the proper expression.
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
var regionLogStr = String.format("didEnterRegion: %s", region.toString());
Log.i(TAG, "onScanResult - I just saw an beacon for the first time! - " + re
}
@Override
public void didExitRegion(Region region) {
Log.i(TAG, "onScanResult - I no longer see an beacon");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
var regionLogStr = String.format("didDetermineStateForRegion: %s, mac: %s", region.toString(), region.getBluetoothAddress());
Log.i(TAG, "onScanResult - I have just switched from seeing/not seeing beacons: " + state + " - " + regionLogStr);
}
});
beaconManager.startMonitoring(new Region("myMonitoringUniqueId", null, null, null));
I could never have any of that callback: didEnterRegion
hit, only the didDetermineStateForRegion
get called when app just started with logging:
onScanResult - I have just switched from seeing/not seeing beacons: 0 - didDetermineStateForRegion: id1: null id2: null id3: null, mac: null
what could be wrong here?
Upvotes: 0
Views: 45
Reputation: 64995
The bottom code shown looks correct to detect any iBeacon with any identifiers using the Android Beacon Library. The top code showing the scan result with direct Android Bluetooth scan APIs shows a scan result that is an iBeacon and should be detectable with the below code for the Android Beacon Library.
There must be some reason other than the code shown that the detection is not working with the library -- perhaps something in code that is not shown.
A few things to check:
Are the required location and scan permissions granted by the user to the app?
Can another app on the same phone also using the Android Beacon Library (e.g. BeaconScope from Google Play or the library) detect the beacon?
Check the troubleshooting steps here: https://altbeacon.github.io/android-beacon-library/detection-trouble.html
You might also try compiling and running the official reference app and see if it detects. If it does, what is different about its code from your code? Java reference app: https://github.com/AltBeacon/android-beacon-library-reference
Upvotes: 0