使用ScheduledTaskAgent更新锁定屏幕 [英] Update lock screen using a ScheduledTaskAgent

查看:73
本文介绍了使用ScheduledTaskAgent更新锁定屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我希望能够使用计划的任务代理更新我的锁屏图像.我确实查看过  这是一篇不错的文章.我的问题是在这段视频中,该视频演示了如何使用以下图片更改背景 您的隔离存储.

I want to be able to update my lockscreen image using a scheduled task agent. I did look at Building Windows Phone 8 Apps Development Jump Start which is a nice article. My problem is in this video it's shown how to change your background with on picture from your isolated storage.

使用:

Uri imageUri = new Uri("ms-appdata:///local/shared/shellcontent/background2.png",                           UriKind.RelativeOrAbsolute);

Which is not my case (I need to download it from a webservice). I builded a small project with a piece of code which should download one image, store it to my isolated storage and then use it to upload my lock screen (I guess it's the best way to do what I want.).

为此,我使用了:

protected override void OnInvoke(ScheduledTask task)
{
    Deployment.Current.Dispatcher.BeginInvoke(() =>
      {
          SavePictureInIsolatedStorage(
              new Uri(
                  "http://www.petfinder.com/wp-content/uploads/2012/11/101418789-cat-panleukopenia-fact-sheet-632x475.jpg"));

         // LockHelper();
          NotifyComplete();
      });

}



And : 

private async void SavePictureInIsolatedStorage(Uri backgroundImageUri)
{

    BitmapImage bmp = new BitmapImage();
    await Task.Run(() =>
                       {

                           var semaphore = new ManualResetEvent(false);
                           Deployment.Current.Dispatcher.BeginInvoke(()=>  
                                   {
                                       bmp = new BitmapImage(backgroundImageUri);
                                       semaphore.Set();
                                   });
                           semaphore.WaitOne();
                       });
    bmp.CreateOptions = BitmapCreateOptions.None;
    WriteableBitmap wbmp = new WriteableBitmap(bmp);

    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        var file = "shared/shellcontent/lockscreen.png";
        // when file exists, delete it
        if (myIsolatedStorage.FileExists(file))
        {
            myIsolatedStorage.DeleteFile(file);
        }

        using (var isoFileStream = new IsolatedStorageFileStream(file, FileMode.Create, myIsolatedStorage))
        {
            // use ToolStackPNGWriterExtensions
            ToolStackPNGWriterLib.PNGWriter.WritePNG(wbmp, isoFileStream);

        }

    }

}


我的问题是我的位图图像似乎未下载.我也遇到了相同的结果,也尝试过使用WebClient.


My issue there is that my bitmap image does not seems to be downloaded. I also tried with a WebClient by I am facing the same result.

注意.

推荐答案

在BitMapImage实例中,您可以预订DownloadProgress,ImageFailed和ImageOpened事件.

In the BitMapImage instance you can subscribe to the DownloadProgress, ImageFailed and ImageOpened events.

bmp += bmp_ImageOpened;

//...

void bmp_ImageOpened(object sender, RoutedEventArgs e)
{
   // Here you know the image is available
}

希望这会有所帮助,
标记

Hope this helps,
Mark


这篇关于使用ScheduledTaskAgent更新锁定屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆