i-beacons 在使用 Alt-beacon 库时在 Xamarin Android 上被过滤。

huangapple go评论59阅读模式
英文:

i-beacons on Xamarin Android getting filtered when using the Alt-beacon library

问题

我认为我已经尽力了。可能在这里漏掉了一些简单的东西。
所以这是设置。我有一个带有依赖服务的 Xamarin Forms 应用程序,它运行 Beacon 监控。它有一个 MonitorNotifier 和一个 RangeNotifier。
我正在使用 alt-beacon 库搜索 iBeacon。我使用的版本是 2.19.4。我创建了一个 Xamarin 绑定,其中包含一些额外的部分类,以便绑定库能够编译。
应用程序要求用户授予 Access_Fine_Location 和 Access_background_location 等权限。
还在运行时请求了蓝牙权限。

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

然后它还请求了运行时位置权限:

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 清单中没有在蓝牙权限中设置 "neverforlocation"。然而,我得到以下消息:

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

我在以下链接中找到了有关基于位置拒绝列表进行过滤的信息,但我没有被拒绝任何位置权限。
我的 Android 版本目标是 13,alt-beacon-binding 也是如此。

编辑:
关于 Beacon 解析器布局:

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);

其中 BeaconLayout 如下图所示:i-beacons 在使用 Alt-beacon 库时在 Xamarin Android 上被过滤。

英文:

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&lt;(string androidPermission, bool isRuntime)&gt;();
            if (Build.VERSION.SdkInt &gt;= BuildVersionCodes.M &amp;&amp; _isAskingFineLocation)
            {
                array.Add((Android.Manifest.Permission.AccessFineLocation, true));
            }

            if (Build.VERSION.SdkInt &gt;= BuildVersionCodes.Q &amp;&amp; _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:
i-beacons 在使用 Alt-beacon 库时在 Xamarin Android 上被过滤。

答案1

得分: 1

在Xamarin或其他抽象框架上使信标检测正常工作始终更加棘手,因为还有另一层可能会引发问题。假设问题不是由Xamarin层引入的(我不是专家,所以无法提供太多帮助),我首先会查看以下几点:

  1. 确保已为iBeacon设置了BeaconParser。默认情况下,AndroidBeaconLibrary仅检测AltBeacon。您需要为iBeacon配置解析器。使用原生Android Kotlin代码,可以这样做:
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. 转到“设置” -> “应用程序” -> “您的应用程序” -> “权限”,非常仔细地查看蓝牙和位置权限,确保它们已被授予。特别要确保位置权限已启用“使用精确定位”开关。

  2. 检查您的合并后的AndroidManifest.xml文件 在此处查看,看看您的BLUETOOTH_SCAN权限是否具有属性“neverForLocation”。如果有的话,必须在声明中删除该标记(可能是由不同的包含库添加的)。要执行此操作,需要在清单中添加一个tools:replace条目。请参见这里

  3. 如果上述方法没有帮助,可以仔细查看Android Beacon Library支持站点上的检测故障排除清单

英文:

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(&quot;m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24&quot;)      
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.

huangapple
  • 本文由 发表于 2023年7月13日 20:49:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定