当前位置: 代码迷 >> Windows Mobile >> wp8中把应用程序设置成锁屏背景解决思路
  详细解决方案

wp8中把应用程序设置成锁屏背景解决思路

热度:93   发布时间:2016-04-25 07:26:35.0
wp8中把应用程序设置成锁屏背景
private async void LockHelper(string filePathOfTheImage, bool isAppResource)
{
    try
    {
        var isProvider = Windows.Phone.System.UserProfile.LockScreenManager.IsProvidedByCurrentApplication;
        if (!isProvider)
        {
            // If you're not the provider, this call will prompt the user for permission.
            // Calling RequestAccessAsync from a background agent is not allowed.
            var op = await Windows.Phone.System.UserProfile.LockScreenManager.RequestAccessAsync();

            // Only do further work if the access was granted.
            isProvider = op == Windows.Phone.System.UserProfile.LockScreenRequestResult.Granted;
        }

        if (isProvider)
        {
            // At this stage, the app is the active lock screen background provider.

            // The following code example shows the new URI schema.
            // ms-appdata points to the root of the local app data folder.
            // ms-appx points to the Local app install folder, to reference resources bundled in the XAP package.
            var schema = isAppResource ? "ms-appx:///" : "ms-appdata:///Local/";
            var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute);

            // Set the lock screen background image.
            Windows.Phone.System.UserProfile.LockScreen.SetImageUri(uri);

            // Get the URI of the lock screen background image.
            var currentImage = Windows.Phone.System.UserProfile.LockScreen.GetImageUri();
            System.Diagnostics.Debug.WriteLine("The new lock screen background image is set to {0}", currentImage.ToString());
        }
        else
        {
            MessageBox.Show("You said no, so I can't update your background.");
  相关解决方案