admin管理员组文章数量:1193728
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?
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?
Share Improve this question edited Jan 26 at 2:12 Shawn asked Jan 23 at 13:44 ShawnShawn 7341 gold badge9 silver badges40 bronze badges1 Answer
Reset to default 0The 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
本文标签: androidAltBeacon Lib can not detect beaconsStack Overflow
版权声明:本文标题:android - AltBeacon Lib can not detect beacons - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738491204a2089716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论