Hello developers
this class is located in MainActivity when launching the app if location permission is true i do
OnStartServiceMessage(null)
public void OnStartServiceMessage(object obj) { Console.WriteLine("Starting Service"); StartService(new Intent(this, typeof(EstimoteMonitoringService))); }
EstimoteMonitoringService
[Service] 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"); _beaconManager.StartMonitoring(_region); _beaconManager.StartMonitoring(_region1); } public override void OnDestroy() { MakeToast("Destroy Service", ToastLength.Short); base.OnDestroy(); } 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; _beaconManager.Connect(this); 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(); start.OnStartServiceMessage(null);
but no use
Can anyone help thank you
From Intent Services in Xamarin.Android,we will see:
It is not possible to stop or interrupt the OnHandleIntent method IntentService while it is working. Because of this design, an IntentService should be kept stateless – it should not rely on an active connection or communication from the rest of the application. An IntentService is meant to statelessly process the work requests.
So we couldn't stop or interrupt the EstimoteMonitoringService
service.
Besides, since the EstimoteMonitoringService
runs in background, so I don't understand the words you said: i want to start the scan in a certain page
.
Answers
From Intent Services in Xamarin.Android,we will see:
So we couldn't stop or interrupt the
EstimoteMonitoringService
service.Besides, since the
EstimoteMonitoringService
runs in background, so I don't understand the words you said:i want to start the scan in a certain page
.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