altBeacon未检测到信标

时间:2015-12-23 08:13:15

标签: c# xamarin beacon

我刚刚尝试实现altbeacon lib。我的问题是永远不会调用回调方法。我只是找不到任何我的信标。我为BeaconManager尝试了一些不同的布局但没有成功。有人能告诉我我做错了什么吗?也许我传递给BeaconManager的Region有问题? 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)

0 个答案:

没有答案