Please help with iBeacon dependency service

Hi, I asked this question in the Forms forum but got no answer and thought I should try here instead maybe cause it´s on the android side I have the problem. I really need to get this to work but can't really figure out how to do it on android in the same way as I do it on ios.

I have this very simple iBeacon reder working i IOS with help of a dependency service and 3 functions.
StartLooking is the important one that takes in a page to report back to, then starts the reading and when it finds beacons it calls a function on the incoming page and send a list of the found beacons.

So as you see very simple functionality but I can't understand how to make the same thing on a android dependency, anyone that can help me, get started?

/magnus

    [assembly: Xamarin.Forms.Dependency(typeof(BeaconListener))]

        namespace xxxx.iOS
        {
            public class BeaconListener:IBeacon
            {
                CLLocationManager lm;
                ScanningPage mp;
                CLBeaconRegion region;

                public BeaconListener()
                {

                }

                public void StartLooking(ScanningPage mPage)
                {
                    mp = mPage;
                    NSUuid beaconId = new NSUuid("00000000-0000-0000-0000-000000000000");
                    region = new CLBeaconRegion(beaconId, "xxxxx");

                    lm = new CLLocationManager();

                    lm.RequestWhenInUseAuthorization();

                    lm.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) =>
                        {
                            if (e.Beacons.Length > 0)
                            {
                                List<Beacon> lb = new List<Beacon>();

                                for (var i = 0; i < e.Beacons.Length;i++) 
                                {
                                    if (e.Beacons[i].Accuracy > 0)
                                    {
                                        var b = new Beacon();
                                        b.minor = e.Beacons[i].Minor.ToString();
                                        b.acc = e.Beacons[i].Accuracy;
                                        b.prox = e.Beacons[i].Proximity.ToString();
                                        lb.Add(b);
                                    }
                                }
                                mp.reciveBeacon(lb);
                            }

                        };
                    lm.StartRangingBeacons(region);

                }

                public void StopLooking()
                {
                    lm.StopRangingBeacons(region);
                }

                public void ResumeLooking() { 
                    lm.StartRangingBeacons(region);
                }
            }
        }
Tagged:

Answers

  • robbitrobbit CNMember ✭✭

    @MagnusWallon
    Hi, I'm a Android developer . I don't know much about Ios . I want to help you , but I don't know if there are some classes only belong to Ios--specific platform in your code. Or you can show your project's requirements. (Page responding to Activity-Android)

  • MagnusWallonMagnusWallon USMember ✭✭

    Hi and thanks for trying to help me!
    The thing is that I'm totally stucked when I came to android. It works so easy when I'm on IOS but I can't find any example for Android that I understand how to transfer to the simple structure below. All I wan't to do is start a function that searches for beacons and when it does find some, send a list of them to a function on a main page.

    The idea is that it should work like this, the main thin is the 3 functions wich builds the dependency service:

    [assembly: Xamarin.Forms.Dependency(typeof(BeaconListener))]

        namespace xxxx.Droid
        {
            public class BeaconListener:IBeacon
            {
                BeaconManager lm;
                ScanningPage mp;
                CLBeaconRegion region;
    
                public BeaconListener()
                {
    
                }
    
                public void StartLooking(ScanningPage mPage)
                {
                    mp = mPage;
           // Set the regionUUid for the beacons
                    NSUuid beaconId = new NSUuid("00000000-0000-0000-0000-000000000000");
                    region = new CLBeaconRegion(beaconId, "xxxxx");
    
                    lm = new BeaconManager();
    
            //function that runs if lm finds beaons
                    lm.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) =>
                        {
                            // create a list(lb) of the found beacons and sort it by closest
    
                //send the list to reciveBeacon function on mainpage "mp"
                                mp.reciveBeacon(lb);
                            }
    
                        };
         // some call for lm to start looking for becons
                    lm.StartRangingBeacons(region);
    
                }
    
                public void StopLooking()
                {
                    lm.StopRangingBeacons(region);
                }
    
                public void ResumeLooking() { 
                    lm.StartRangingBeacons(region);
                }
            }
        }
    
Sign In or Register to comment.