Forum Xamarin.Android

Calling MainActivity class in another. ContentPage

soufianemarlysoufianemarly Member ✭✭✭
edited February 2020 in Xamarin.Android

Hello developers
this class is located in MainActivity when launching the app if location permission is true i do

        public void OnStartServiceMessage(object obj)
            Console.WriteLine("Starting Service");
            StartService(new Intent(this, typeof(EstimoteMonitoringService)));


    public class EstimoteMonitoringService : IntentService, BeaconManager.IServiceReadyCallback 
        private BeaconManager _beaconManager;
        private Region _region;
        private Region _region1;

        public void OnServiceReady()
            MakeToast("Service is Ready", ToastLength.Short);

            Console.WriteLine("Service is Ready");

        public override void OnDestroy()
            MakeToast("Destroy Service", ToastLength.Short);
        protected override void OnHandleIntent(Intent intent)
            Console.WriteLine(" zoukoukou");
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
            _region = new Region("beacon1", "fda50694-a4e3-4fb1-afcf-c6ac07647821");
            _region1 = new Region("beacon2", "fda50694-a4e3-4fb1-afcf-c6ac07647822");
            _beaconManager = new BeaconManager(Application.Context);
            _beaconManager.SetBackgroundScanPeriod(TimeUnit.Seconds.ToMillis(1), TimeUnit.Seconds.ToMillis(10));
            _beaconManager.EnteredRegion += OnEnteredRegion;
            _beaconManager.ExitedRegion += OnExitedRegion;
            return StartCommandResult.Sticky;
        public void OnExitedRegion(object sender, BeaconManager.ExitedRegionEventArgs e)
            Console.WriteLine("Beacon not in range ");

        public async void OnEnteredRegion(object sender, BeaconManager.EnteredRegionEventArgs e)
            Console.WriteLine("Enter region");
            foreach (var beacon in e.Beacons)
                Console.WriteLine("Beacon ProximityUUID " + beacon.ProximityUUID);
                Console.WriteLine("Beacon Major " + beacon.Major);
                Console.WriteLine("Beacon Minor " + beacon.Minor);
                Console.WriteLine("Beacon Rssi " + beacon.Rssi);

Scanning for beacon begin
but i want to start the scan in a certain page how can i do that

i tried to do stuff like

    MainActivity start = new MainActivity();

but no use

Can anyone help thank you

Best Answer


  • soufianemarlysoufianemarly Member ✭✭✭

    my application is for students when a student is present in a course it is necessary that he open the application and select the current course then there is a clickable button which makes a call to a web service which returns contains the uuid, it is in this part where I must launch the detection of beacon

Sign In or Register to comment.