首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

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

2013-03-14 
wp8中把应用程序设置成锁屏背景private async void LockHelper(string filePathOfTheImage, bool isAppRes

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.");


        }
    }
    catch (System.Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
}

这方法在哪调用?
[解决办法]
你希望在什么条件触发,就到对应事件的响应中调用该函数。

热点排行