Ibeacon发射器xmarin Android

时间:2018-03-13 11:54:12

标签: android bluetooth xamarin.android ibeacon

我想要一个信标消息,我使用 nuget 下载的 AndroidAltBeaconLibrary

BeaconTransmitter mBeaconTransmitter = new BeaconTransmitter(
                                          this,newBeaconParser().SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")
                                         );   
List<Java.Lang.Long> listNew = new List<Java.Lang.Long>(
                                new Java.Lang.Long[] {
                                  (Java.Lang.Long)0l 
                                });

Beacon beacon = new Beacon.Builder()
                    .SetId1("FDA50693-A4E2-4FB1-AFCF-C6EB07647825")
                    .SetId2("1000") //Major
                    .SetId3("2000") //Minor
                    .SetManufacturer(0x004C)
                    .SetTxPower(-59)
                    .SetDataFields(listNew)
                    .Build();
mBeaconTransmitter.StartAdvertising(beacon);

代码有效,但如何在StartAdvertising中实现AdvertiseCallback?(c#code)

1 个答案:

答案 0 :(得分:0)

只需创建一个继承AdvertiseCallback

的类
private class NotyficationIBecon : AdvertiseCallback
    {
        private BeaconTransmitter _Itx;

        public NotyficationIBecon(BeaconTransmitter Itx) {
            this._Itx = Itx;
        }

        public override void OnStartFailure([GeneratedEnum] AdvertiseFailure errorCode)
        {
            base.OnStartFailure(errorCode);
        }
        public override void OnStartSuccess(AdvertiseSettings settingsInEffect)
        {
            base.OnStartSuccess(settingsInEffect);
        }
    }

并将类实例传递给方法StartAdvertising:

NotyficationIBecon callback = new NotyficationIBecon(mBeaconTransmitter)
mBeaconTransmitter.StartAdvertising(beacon, callback);