0

I am opening location setting in my application, like this:

await Launcher.LaunchUriAsync(new Uri("ms-settings-location:"));

but when location settings open and user turn on location and go back, no event is fired. How can I know that user has returned from settings so that I can check whether user has open location settings or not ... onnavigatedto and and onnavigatedfrom event are not fired while returning and going from my application page respectively.

Yawar
  • 1,924
  • 3
  • 29
  • 39

2 Answers2

1

Lets say you implement the following code:

Window.Current.VisibilityChanged += Current_VisibilityChanged;
Window.Current.SizeChanged += Current_SizeChanged;
Window.Current.Activated += Current_Activated;
Window.Current.Closed += Current_Closed;
App.Current.Resuming += Current_Resuming;
App.Current.Suspending += Current_Suspending;

Action Panel

Action Panel

None of the above events will be raised if the action panel opens, yes nothing!

Settings

If the user tappes the ALL SETTINGS then it will navigate to the Settings Page and a few events will be raised:

  • Current_VisibilityChanged
  • Current_Closed
  • Current_Suspending

returning to the app

  • Current_Resuming
  • Current_VisibilityChanged
  • Current_Activated

Geolocator (the solution)

Inside the Geolocator class there is a StatusChanged event to which you should subscribe.

If the user switched Location on then you should wait for StatusChangedEventArgs.Status to become Ready before you continue to try and acquire the position, and if it becomes Disabled then stop.

It is much better to subscribe to this event because it allows you to know exactly what is going on.

Barnstokkr
  • 2,904
  • 1
  • 19
  • 34
  • GeoLocator solution seems best to me, I have applied a weird solution for now, will try this and then mark this as answer if it solve my problem – Yawar Aug 13 '15 at 08:24
0

There surely will be some events fired, you can probably use:

  • Suspending/Resuming events. Your app will be suspended soon after user navigates to settings. Only watch out, hence while debugging the PLM is disabled and Suspending/Resuming event won't be raised - you will have to test in using Lifecycle events tab,
  • subscribe to Windows.VisibilityChanged event - you will have to handle this event carefully, as it's fired in much more cases that Suspending event,
  • subsribe to Windows.Activated event - like above, it's fired even more times than VisivilityChanged.

Probably the best choice will be Suspending event. With this you can also handle case when you app was terminated by OS.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154