0

I think I have tried all that I could. May be missing something simple here. So here is the setup. I have a Xamarin forms application with a dependency service which runs beacon monitoring. It has a MonitorNotifier and a RangeNotifier. I'm searching for iBeacon using the alt-beacon library. I'm on 2.19.4.I created a Xamarin bindings with some additional partial classes so that the binding library would compile. The application asks user for Access_Fine_Location and Access_background_location etc. Bluetooth permissions are also asked at runtime.

(Android.Manifest.Permission.BluetoothScan, true),
(Android.Manifest.Permission.BluetoothConnect, true),           
(Android.Manifest.Permission.BluetoothAdmin, true)

then it also asks for runtime location permissions:

            var array = new List<(string androidPermission, bool isRuntime)>();
            if (Build.VERSION.SdkInt >= BuildVersionCodes.M && _isAskingFineLocation)
            {
                array.Add((Android.Manifest.Permission.AccessFineLocation, true));
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Q && _isAskingBackgroundLocation)
            {
                array.Add((Android.Manifest.Permission.AccessBackgroundLocation,true));
            }
            return array.ToArray();

Android Manifest does not have "neverforlocation" set in bluetooth permissions. And yet, I get the following:

07-13 18:27:50.990 V/BtGatt.GattService( 4285): Skipping data matching denylist: ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0a834234-e4a6-4fbd-a596-383e852d706f], mServiceSolicitationUuids=[], mManufacturerSpecificData={76=[2, 21, 111, 112, 45, -123, 62, 56, -106, -91, -67, 79, -90, -28, 52, 66, -125, 10, 0, 0, -33, 126, -59]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=ACS Beacon, mTransportBlocks=[]]
07-13 18:27:50.990 I/BtGatt.GattService( 4285): Skipping client for location deny list
07-13 18:27:50.990 V/BtGatt.GattService( 4285): Skipping data matching denylist: ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0a834234-e4a6-4fbd-a596-383e852d706f], mServiceSolicitationUuids=[], mManufacturerSpecificData={76=[2, 21, 111, 112, 45, -123, 62, 56, -106, -91, -67, 79, -90, -28, 52, 66, -125, 10, 0, 0, -33, 126, -59]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=ACS Beacon, mTransportBlocks=[]]
07-13 18:27:50.990 I/BtGatt.GattService( 4285): Skipping client for location deny list
07-13 18:27:50.991 V/BtGatt.GattService( 4285): Skipping data matching denylist: ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0a834234-e4a6-4fbd-a596-383e852d706f], mServiceSolicitationUuids=[], mManufacturerSpecificData={76=[2, 21, 111, 112, 45, -123, 62, 56, -106, -91, -67, 79, -90, -28, 52, 66, -125, 10, 0, 0, -33, 126, -59]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=ACS Beacon, mTransportBlocks=[]]
07-13 18:27:50.991 I/BtGatt.GattService( 4285): Skipping client for location deny list
07-13 18:27:50.991 V/BtGatt.GattService( 4285): Skipping data matching denylist: ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0a834234-e4a6-4fbd-a596-383e852d706f], mServiceSolicitationUuids=[], mManufacturerSpecificData={76=[2, 21, 111, 112, 45, -123, 62, 56, -106, -91, -67, 79, -90, -28, 52, 66, -125, 10, 0, 0, -33, 126, -59]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=ACS Beacon, mTransportBlocks=[]]
07-13 18:27:50.991 I/BtGatt.GattService( 4285): Skipping client for location deny list

I found on

https://android.googlesource.com/platform/packages/apps/Bluetooth/+/master/src/com/android/bluetooth/gatt/GattService.java

about filtering based on location deny list, but I don't have any location permission denied. My Android is targeting 13. So is the alt-beacon-binding.

Edit: Regarding the beacon parser layout:

var parser = new BeaconParser();
parser.SetBeaconLayout(Constants.BeaconLayout);
parser.SetHardwareAssistManufacturerCodes(new int[]{0x004c});

_beaconManager = BeaconManager.GetInstanceForApplication(Application.Context);
            _beaconManager.BeaconParsers.Clear();
            _beaconManager.BeaconParsers.Add(parser);

where BeaconLayout is this: enter image description here

zyzzyxx
  • 323
  • 2
  • 9

1 Answers1

1

It is always extra tricky to get beacon detection working on Xamarin or other abstraction frameworks, because there is yet another layer that can cause problems. Assuming the problem is not introduced by the Xamarin layer (I am no expert there, so I cannot offer much help), the first things I would look at are:

  1. Make sure you have a BeaconParser set up for iBeacon. By default, the AndroidBeaconLibrary only detects AltBeacon. You have to configure a parser for iBeacon. With native Android Kotlin code, you do that like this:
val parser = BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")      
beaconManager.getBeaconParsers().add(parser)
  1. Go to Settings -> Apps -> Your App -> Permissions and look very closely at the Bluetooth and Location permissions to make sure they are granted. In particular make sure the Location permission as the "Use Precise Location" switch turned on.

  2. Check your merged AndroidManifest.xml file see here to see if your BLUETOOTH_SCAN permission has the attribute “neverForLocation”. If it is, you must remove that marking in the declaration. (It may get added by a different included library.) Doing this requires a tools:replace entry in your manifest. See here.

  3. If the above doesn't help, go thorough this detection troubleshooting checklist on the Android Beacon Library support site.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • As per the troubleshooting checklist, I do get DidDetermineStateForRegion:```public void DidDetermineStateForRegion(int state, Region region) { Debug.WriteLine($"didDetermineStateForRegion called with state: " + (state == 1 ? "INSIDE ("+state+")" : "OUTSIDE ("+state+")")); }```. But I think the issue is not whether I'm getting a call back, the issue I think is Android filtering out the beacon due to some deny list. Similar to this one:https://github.com/AltBeacon/android-beacon-library/issues/1063. Or, that message from Android console can be disregarded? – zyzzyxx Jul 13 '23 at 14:16
  • Does the library only works if the Beacon monitoring and ranging is done on an activity? Or is that an Android thing? – zyzzyxx Jul 13 '23 at 19:21
  • 1
    Please see point 3 in my edited answer for another possible cause. No, beacon ranging and monitoring do not need to be in an activity. – davidgyoung Jul 13 '23 at 22:18
  • thanks for adding that point. However, it didn't help. What helped was couple of things: Moved my beacon ranging and mornitoring code to mainactivity. I copied the exact sequence of calls as in the BeaconReference kotlin app. Except all of that was done after Xamarin calls the ```LoadApplication(new App())``` in MainActivity. Also, the differentiating factor seems to be this like ```_beaconManager.SetIntentScanningStrategyEnabled(false);``` . based on the comment on the beaconReferenceApp, the strategy should be set to true? or I'm mis-interpreting it?. – zyzzyxx Jul 14 '23 at 13:30
  • Continued from above: ```// Ranging callbacks will drop out if no beacons are detected // Monitoring callbacks will be delayed by up to 25 minutes on region exit beaconManager.setIntentScanningStrategyEnabled(true)``` – zyzzyxx Jul 14 '23 at 13:30
  • 1
    The default value for intentScanningStrategyEnabled is false, so adding extra code to set it to that default value should have no effect unless another layer of code changed it. – davidgyoung Jul 14 '23 at 16:50
  • Thanks. What does intentscanningstrategy actually do? In the reference app it was set to true. Just Trying to understand the behavior. – zyzzyxx Jul 15 '23 at 17:18
  • Docs for the Intent Scanning Strategy [here](https://altbeacon.github.io/android-beacon-library/detection_times.html). This is default off in the master branch of the Kotlin reference app, but you can [uncomment this line](https://github.com/davidgyoung/android-beacon-library-reference-kotlin/blob/master/app/src/main/java/org/altbeacon/beaconreference/BeaconReferenceApplication.kt#L76) to enable it. – davidgyoung Jul 16 '23 at 21:48