1

我只是试图实现 altbeacon 库。我的问题是永远不会调用回调方法。我就是找不到我的任何信标。我为 BeaconManager 尝试了几种不同的布局,但均未成功。有人可以告诉我我做错了什么吗?也许我传递给 BeaconManager 的区域有问题?altbeacon 在哪里使用 Region 的第一个参数Region(java.lang.String uniqueId, Identifier id1, Identifier id2, Identifier id3)?我为所有其他参数传递了 null,因为我不想找到特定的信标。

namespace DMSBeacon
{
    [Activity(Label = "Altbeacon")]
    public class AltbeaconActivity : Activity, IBeaconConsumer,     IDialogInterfaceOnDismissListener
    {
        private BeaconManager oBeaconManager;
        private MonitorNotifier oNotifier = new MonitorNotifier();
        private RangeNotifier oRangeNotifier = new RangeNotifier();

        public class RangeNotifier : IRangeNotifier
        {
            public IntPtr Handle
        {
            get
            {
                //throw new NotImplementedException();
                return new IntPtr();
            }
        }

        public void DidRangeBeaconsInRegion(ICollection<Beacon> beacons, Region region)
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }


    public class MonitorNotifier : IMonitorNotifier
    {
        public IntPtr Handle
        {
            get
            {
                //throw new NotImplementedException();
                return new IntPtr();
            }
        }
        public void DidDetermineStateForRegion(int state, Region region)
        {
            Android.Util.Log.Info("TEST", "I have just switched from seeing/not seeing beacons: " + state);
        }

        public void DidEnterRegion(Region region)
        {
            Android.Util.Log.Info("TEST", "I just saw an beacon for the first time!");
        }

        public void DidExitRegion(Region region)
        {
            Android.Util.Log.Info("TEST", "I no longer see an beacon");
        }
        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }
    public void OnBeaconServiceConnect()
    {
        oBeaconManager.SetRangeNotifier(oRangeNotifier);
        //oBeaconManager.SetMonitorNotifier(oNotifier);            
        oBeaconManager.StartRangingBeaconsInRegion(new Region("allbeacons", null, null, null));
        //oBeaconManager.StartMonitoringBeaconsInRegion(new Region("allbeacons", null, null, null));

    }
    protected override void OnDestroy()
    {
        base.OnDestroy();
        oBeaconManager.Unbind(this);
    }
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.notify);
        oBeaconManager = BeaconManager.GetInstanceForApplication(this);            
        oBeaconManager.BeaconParsers.Add(new BeaconParser()
           .SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
        oBeaconManager.Bind(this);                       
    }

    public void OnDismiss(IDialogInterface dialog)
    {
        throw new NotImplementedException();
    }      
}

}

编辑:

如果我查看我的 Android 设备日志,我可以在以下几行中看到我的信标

(12-23 09:46:30.455 D/bt_btif_gattc(12179): btif_gattc_update_properties BLE device name=BEACON D1:95:12 len=15 dev_type=2
12-23 09:46:30.519 D/bt_btif_gattc(12179): btif_gattc_update_properties BLE device name=Kontakt1234567 len=14 dev_type=2
12-23 09:46:30.658 D/bt_btif_gattc(12179): btif_gattc_update_properties BLE device name=Kontakt len=7 dev_type=2
12-23 09:46:30.699 D/bt_btif_gattc(12179): btif_gattc_update_properties BLE device name=BEACON D1:0C:AF len=15 dev_type=2)
4

0 回答 0