2013-08-20 1 views
1

IsolatedStorage에 이미지가 있으며 장치 잠금 화면 배경으로 프로그래밍 방식으로 설정하고 싶습니다. 제 문제는 LockScreen.SetImageUri에 필요한 올바른 경로를 얻을 수 없다는 것입니다. http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206968(v=vs.105).aspx을 참조하면``ms-appdata : /// local/''이 로컬 이미지에 필요한 선구자임을 알 수 있습니다.LockScreen.SetImageUri를 사용하여 Windows Phone 8 잠금 화면 배경 설정 방법

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

나는 JPG 이미지가 CameraCaptureTask에서 저장되는 Pictures라고 IsolatedStorage 내 응용 프로그램에서 폴더를 만들었습니다. 나는 위의 기법을 통해이 폴더 내 이미지에 액세스 할 수있는 몇 가지 방법을 시도했지만 나는 항상 디버깅 할 때

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

은, 그러나, 나는 uri = "ms-appdata:///Local/Pictures/WP_20130812_001.jpg" 것을 어떻게이 해결되지 않은 참조 다음 회선에 자동 ArgumentException을받을 수?

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

}

가 어떻게 적절한 예상 URI에 LockScreen.SetImageUri을 수정할 수는 다음과 같이

내 구현은?

답변

1

앱에서 화면 이미지 잠금을 설정하려면 앱을 잠금 화면 공급자로 선언 할 수 있습니다. 다음과 같은 태그를 추가하여 WMAppManifest.xml 파일을 수정하여 해당 작업을 수행 할 수 있습니다

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

확인 당신이 당신의 매니페스트 파일에이 태그가 있는지.

+0

감사합니다. 이미 완료했습니다. – Matthew

+0

내가 배치,주의 내' ...'너무 ' <확장 ExtensionName 서 = "LockScreen_Background"ConsumerID = 같은 폐쇄'Token' 태그에서 "{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID = "_ default"/> Matthew

0

귀하의 문제를 해결하는 데 도움이되기를 바랍니다.

앱이 이미 설치된 경우 배경 이미지 제공 업체인지 확인하십시오. 그렇지 않다면 설정 -> 화면 잠금 -> 배경으로 이동하여 목록에서 응용 프로그램을 선택하십시오.

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

1. 선언 응용 프로그램 매니페스트 파일 편집 WMAppManifest.xml는 XML 편집기에서 응용 프로그램의 의도는 다음과 같은 확장이 존재 확인 : 프로그래밍 측면에서

2. 배경 이미지를 변경하는 코드 작성 다음은 배경 설정 코드를 작성하는 방법의 예입니다.URI를 관련하여

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

, 거기에 많은 옵션이 있지만, 마음에 계속 :

사용하는 앱에 제공되는 이미지를 사용하려면 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); 
+0

작동하는 샘플은 http://developer.nokia.com/Community/Wiki/Dynamic_Lock_Screen_for_Windows_Phone_8에서 확인할 수 있습니다 – hmadrigal