1

IsolatedStorage に画像があり、プログラムでデバイスのロック画面の背景として設定したいと考えています。私の問題は、 が必要とする正しいパスを取得できないことですLockScreen.SetImageUrihttp://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206968(v=vs.105).aspxを参照すると、「ms-appdata:///local/」がローカル イメージに必要な前駆体。

var schema = isAppResource ? "ms-appx:///" : "ms-appdata:///Local/";
var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute);

PicturesCameraCaptureTask から jpg 画像が保存される、アプリケーションの IsolatedStorage というフォルダーを作成しました。上記のスキームを使用してこのフォルダー内の画像にアクセスする方法をいくつか試しましたが、常にArgumentException次の行で

Windows.Phone.System.UserProfile.LockScreen.SetImageUri(uri);

しかし、デバッグ時に が表示されuri = "ms-appdata:///Local/Pictures/WP_20130812_001.jpg"ます。なぜこれが正しくないのでしょうか?

私の実装は次のとおりです

private void recent_SelectionChanged(object sender, SelectionChangedEventArgs e)
{            
    capturedPicture = (sender as LongListSelector).SelectedItem as CapturedPicture;

    if (capturedPicture != null)
    {
        //filename is the name of the image in the IsolatedStorage folder named Pictures
        fileName = capturedPicture.FileName;
    }
}

void setAsLockScreenMenuItem_Click(object sender, EventArgs e)
{
    if (!String.IsNullOrEmpty(fileName)) 
    {
        //PictureRepository.IsolatedStoragePath is a string = "Pictures"                
        //LockHelper("isostore:/" + PictureRepository.IsolatedStoragePath + "/" + fileName, false);  //results in FileNotFoundException
        LockHelper(PictureRepository.IsolatedStoragePath + "/" + fileName, false);  //results in ArgumentException
    }
    else
    {
        MessageBoxResult result = MessageBox.Show("You must select an image to set it as your lock screen.", "Notice", MessageBoxButton.OK);
        if (result == MessageBoxResult.OK)
        {
            return;
        }
    }
}

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());
}

}

LockScreen.SetImageUri適切な予想される uriに変更するにはどうすればよいですか?

4

2 に答える 2

0

これが問題に対処するのに役立つことを願っています。

アプリが既にインストールされている場合は、それが背景画像プロバイダーであることを確認してください。そうでない場合は、[設定] -> [ロック画面] -> [背景] に移動し、リストからアプリケーションを選択します。

プログラマティック側:

1. アプリケーション マニフェスト ファイルでアプリの意図を宣言します XML エディターで WMAppManifest.xml を編集し、次の拡張子が存在することを確認します。

<Extensions> <Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> </Extensions>

2. 背景画像を変更する コードの記述 背景を設定するコードの記述例を次に示します。

private async void lockHelper(Uri backgroundImageUri, string backgroundAction)
        {
            try
            {
                //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 LockScreenManager.RequestAccessAsync();
                //Check the status to make sure we were given permission. 
                bool isProvider = LockScreenManager.IsProvidedByCurrentApplication; if (isProvider)
                {
                    //Do the update. 
                    Windows.Phone.System.UserProfile.LockScreen.SetImageUri(backgroundImageUri);
                    System.Diagnostics.Debug.WriteLine("New current image set to {0}", backgroundImageUri.ToString());
                }
                else { MessageBox.Show("You said no, so I can't update your background."); }
            }
            catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
        }

Uris に関しては、多くのオプションがありますが、次の点に注意してください。

アプリで配布したイメージを使用するには、ms-appx:/// を使用します。

Uri imageUri = new Uri("ms-appx:///background1.png", UriKind.RelativeOrAbsolute); LockScreen.SetImageUri(imageUri);

ローカル フォルダーに保存されているイメージを使用するには、ms-appdata:///local/shared/shellcontent を使用 します /shared/shellcontent サブフォルダー内またはそれ以下にある必要があります

Uri imageUri = new Uri("ms-appdata:///local/shared/shellcontent/background2.png", UriKind.RelativeOrAbsolute); LockScreen.SetImageUri(imageUri);
于 2013-11-19T16:07:34.060 に答える