繁体   English   中英

Windows Phone 8.1背景位置跟踪

[英]Windows phone 8.1 background location tracking

我需要在Windows Phone 8.1上执行一个应用程序,该应用程序在后台任务中每15分钟更新一次我的位置。

即使用户不在场,该任务也必须工作。 我怎样才能做到这一点 ?

我刚刚创建了BackgroundTaskTimeTrigger注册了它,但是它不起作用。

这是我的注册方法:

var access = await BackgroundExecutionManager.RequestAccessAsync();
BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
IBackgroundTrigger trigger = new TimeTrigger(15, false);
builder.Name = "BackgroundTask";
builder.SetTrigger(trigger);
builder.TaskEntryPoint = typeof(LocationTask).FullName;
BackgroundTaskRegistration register = builder.Register();

这是我的LocationTask

public sealed class LocationTask : IBackgroundTask
{
    public async void Run(IBackgroundTaskInstance taskInstance)
    {
        try
        {
            Geolocator geolocator = new Geolocator();
            Geoposition geoposition = await geolocator.GetGeopositionAsync();
            Risorse.lat = Math.Round(geoposition.Coordinate.Point.Position.Latitude, 6);
            Risorse.lon = Math.Round(geoposition.Coordinate.Point.Position.Longitude, 6);
            DrupalBridge db = new DrupalBridge("http://interventi.computerhalley.it", "/rest", Risorse.utente, Risorse.lat.ToString().Replace(',', '.'), Risorse.lon.ToString().Replace(',', '.'));
            db.postCoordinate();
        }
        catch (Exception ex)
        {
            if ((uint)ex.HResult == 0x80004004)
            {
                MessageDialog messaggio = new MessageDialog("GPS disattivato...l'applicazione verrà chiusa...\r\nRiavviarla dopo aver attivato la geolocalizzazione");
                await messaggio.ShowAsync();
                Application.Current.Exit();
                //await Windows.System.Launcher.LaunchUriAsync(new Uri("ms - impostazioni - posizione"));
            }
            else
            {
                MessageDialog messaggio = new MessageDialog("Errore imprevisto\r\nriavviare l'applicazione...");
                await messaggio.ShowAsync();
                Application.Current.Exit();
                // something else happened acquring the location
            }
        }
    }
}

我假设您输入的值15出现异常。

但是,在Windows Phone 8.1中,时间触发时间最少为30分钟,Windows存储应用程序最少为15分钟。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM