Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

W10 UWP - Set remote image as desktop wallpaper / lockscreen

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.

like image 251
Travis Liew Avatar asked Aug 06 '15 14:08

Travis Liew


People also ask

How do I set common wallpaper for domain users?

To change the wallpaper in a domain user account, you must first have administrator privileges. Then, open the Control Panel and go to the "User Accounts" section. Select the "Change your desktop background" link. Choose the image you want to use as your wallpaper, and then click the "Save Changes" button.

How do I override my desktop background?

Under Local Computer Policy, expand User Configuration, expand Administrative Templates, expand Desktop, and then click Active Desktop. Double-click Active Desktop Wallpaper. On the Setting tab, click Enabled, type the path to the desktop wallpaper that you want to use, and then click OK.


1 Answers

Save your remote image to ApplicationData.Current.LocalFolder first, then use TrySetWallpaperImageAsync/TrySetLockScreenImageAsync and point to the saved image instead of directly referencing the remote image should work.

like image 59
Nik A. Avatar answered Sep 29 '22 00:09

Nik A.