2

我做了一个后台任务,让它监听 NetworkStateChange,效果很好。

我正在尝试通过启动程序 Windows.System.Launcher.LaunchUriAsync但尝试时出现访问被拒绝异常:

这是任务的来源:

namespace Tasks
{
    public sealed class Upload : IBackgroundTask
    {
        BackgroundTaskDeferral _deferral = null;
        private bool wifiConnected = false;

        public bool WiFiConnected
        {
            get
            {
                return wifiConnected;
            }
            set
            {
                if (value == wifiConnected)
                    return;

                wifiConnected = value;
            }
        }


        public void Run(IBackgroundTaskInstance taskInstance)
        {

            var InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
            WiFiConnected = InternetConnectionProfile != null;

            if (!WiFiConnected)
            {
                LaunchFlexCheck();
                return;
            }


            _deferral = taskInstance.GetDeferral();
            _deferral.Complete();
        }

        private async void LaunchFlexCheck()
        {
            Debug.WriteLine("BEFORE LaunchFlexCheck()");
            bool result = false;
            try
            {
                result = Windows.System.Launcher.LaunchUriAsync(new System.Uri("myapp:MainPage")).GetResults();
            }
            catch (Exception e)
            {
                result = false;
                Debug.WriteLine("LaunchFlexCheck exception:" +  e.Message );
            }

            Debug.WriteLine("LaunchFlexCheck succes:" + (result ? "true" : "false"));
            Debug.WriteLine("AFTER LaunchFlexCheck()");
        }

    }
}

有可能这样做吗?

4

1 回答 1

3

从后台任务启动应用程序意味着用户将在他正在做的事情中被打断,以启动他没有请求的应用程序。这与 Windows Phone 的设计准则完全矛盾,在该准则中,用户必须始终保持控制。因此,我相信这是不可能的。

于 2014-11-06T11:33:41.677 回答