1

我正在尝试创建一个后台任务,该任务将在系统检测到由 estimote 信标广播的 eddystone 广告时运行。

我已经将信标配置为发送 eddystone 数据包,并且我曾经UniversalBeaconLibrary在应用程序处于前台时获取这些数据包(这里没有问题)。

现在我想在应用程序未启动时收到通知(使用对蓝牙广播数据包作出反应的后台任务)。据我了解,为了避免对电池/CPU 造成太大压力,我确实需要过滤这些广告。

最简单的过滤形式之一(我尝试使用的)是使用蓝牙 SIG 提供的公司 ID。

这是我尝试过的:

public static async void Register()
{
    if (BackgroundTaskRegistration.AllTasks.Count == 0)
    {
        var trigger = MakeTrigger();

        // this is needed for Phone, not so for Windows in this case.  
        var allowed = await BackgroundExecutionManager.RequestAccessAsync();

        if ((allowed != BackgroundAccessStatus.Denied) &&
            (allowed != BackgroundAccessStatus.Unspecified))
        {
            BackgroundTaskBuilder builder = new BackgroundTaskBuilder
            {
                Name = "BLEWatcher",
                TaskEntryPoint = typeof(BLEBackgroundConsumer.Consumer).FullName
            };
            builder.SetTrigger(trigger);
            builder.Register();
        }
    }
}
private static BluetoothLEAdvertisementWatcherTrigger MakeTrigger()
{
    var trigger = new BluetoothLEAdvertisementWatcherTrigger();
    //Can add some filters here
    //trigger.AdvertisementFilter.Advertisement.ManufacturerData.Add(new BluetoothLEManufacturerData()
    //{
    //    CompanyId = 349 //Estimote
    //});
    //trigger.AdvertisementFilter.Advertisement.ManufacturerData.Add(new BluetoothLEManufacturerData()
    //{
    //    CompanyId = 76 // Apple
    //});
    //trigger.AdvertisementFilter.Advertisement.ManufacturerData.Add(new BluetoothLEManufacturerData()
    //{
    //    CompanyId = 224 // Google
    //});
    return (trigger);
}

因为它是我得到一个例外,说没有足够或太多的过滤。

取消注释其中一个触发块时,我没有例外,但任务似乎没有启动。

**编辑:** 我问估计他们在使用 eddystone 数据包时广播的公司 ID 是什么。据他们说,没有。

关于这个答案,什么是合适的过滤器?

4

1 回答 1

1

蓝牙 SIG 公司 ID 仅与制造商蓝牙 LE 广告一起使用,例如 iBeacon 和 AltBeacon。Eddystone 使用不包含公司 ID 的服务蓝牙 LE 广告。相反,它们包含 0xFEAA 的 16 位服务 UUID。

有关更多详细信息,请参见此处: https ://github.com/google/eddystone/blob/master/protocol-specification.md

于 2016-01-09T00:35:17.863 回答