I'm trying to set a remote image as the desktop wallpaper / phone lockscreen in my W10 UWP app:
string name = "test_image.jpg";
Uri uri = new Uri("http://www.ucl.ac.uk/news/news-articles/1213/muscle-fibres-heart.jpg");
// download image from uri into temp storagefile
var file = await StorageFile.CreateStreamedFileFromUriAsync(name, uri, RandomAccessStreamReference.CreateFromUri(uri));
// file is readonly, copy to a new location to remove restrictions
var file2 = await file.CopyAsync(KnownFolders.PicturesLibrary);
// test -- WORKS!
//var file3 = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Design/1.jpg"));
// try set lockscreen/wallpaper
if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) // Phone
success = await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(file2);
else // PC
success = await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(file2);
file1
doesn't work as it is read-only, so I copy it to a new location (pictures library) to remove restrictions -> file2
.
Note: file3
works, so I'm not sure what's happening -- I assume TrySetWallpaperImageAsync/TrySetLockScreenImageAsync
only accepts msappx
local files...
Anyone have any ideas on work arounds?
Thanks.