Search code examples
c#geolocationwindows-phonewin-universal-appwindows-10

Location tracking in background with Universal Windows 10 app


I am trying to "refresh" an old Windows Phone 8.0 app that needs location tracking in the background. It's not possible to "upgrade" it to Windows Phone 8.1 (as the background location tracking does not work).

I need to fetch the position let's say every minute. If I migrate the app to Windows 10 UAP will the location tracking in the background work?


Solution

  • The UAP means of background tracking is handled by an ExtendedExecutionSession (at least in the March 2015 Tech Preview):

    private ExtendedExecutionSession session;
    
    private async void StartLocationExtensionSession()
    {
       session = new ExtendedExecutionSession();
       session.Description = "Location Tracker";
       session.Reason = ExtendedExecutionReason.LocationTracking;
       session.Revoked += ExtendedExecutionSession_Revoked;
       var result = await session.RequestExtensionAsync();
       if (result == ExtendedExecutionResult.Denied)
       {
           //TODO: handle denied
       }
    }
    

    This example comes from http://www.sharpgis.net/post/2015/03/29/Using-Windows-10s-Extended-Execution.