Windows Phone 8의 잠금 화면 배경
2013-03-11
적용 대상: Windows Phone 8 전용입니다.
Windows Phone 8 에서 사용자는 잠금 화면 배경 이미지 공급자로서 앱을 사용하도록 선택할 수 있습니다.

앱이 휴대폰에서 잠금 화면 배경 이미지를 제공할 수 있도록 하려면 앱 매니페스트 파일에서 앱의 목적을 선언하고 코드를 추가하여 배경 이미지 변경을 처리해야 합니다.
이 항목에는 다음 단원이 포함되어 있습니다.
휴대폰에 잠금 화면 배경 이미지를 제공하려면 먼저 앱 매니페스트 파일을 업데이트하여 앱을 잠금 화면 배경 공급자로 선언해야 합니다.
솔루션 탐색기에서 속성을 확장하고 WMAppManifest.xml을 마우스 오른쪽 버튼으로 클릭한 다음 연결 프로그램을 클릭하고 소스 코드(텍스트 편집기)(인코딩 사용)을 선택합니다.
<Extensions> 요소에서 잠금 화면 배경 <Extension> 요소를 추가합니다. <Extensions> 요소가 파일에 나타나지 않으면 다음 전체 코드 예제를 파일에 배치합니다. <Extensions> 요소는 <Tokens> 요소 아래에 배치해야 합니다.
<Extensions> <Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> </Extensions>
다음 코드 예제에서는 사용자가 지정된 버튼을 탭할 때 잠금 화면 배경 이미지를 변경하는 방법을 보여 줍니다.
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()); } }
고유한 이미지 이름
격리된 저장소에서 잠금 화면 배경 이미지를 업데이트하는 경우 업데이트할 때마다 고유한 파일 이름을 제공해야 합니다. 이 작업은 파일 이름에 대해 A/B 전환 논리를 구현하면 쉽게 수행할 수 있습니다.
다음 코드에서는 A/B 전환 논리의 예를 보여 줍니다.
string fileName; var currentImage = LockScreen.GetImageUri(); if (currentImage.ToString().EndsWith("_A.jpg")) { fileName = "LiveLockBackground_B.jpg"; } else { fileName = "LiveLockBackground_A.jpg"; } var lockImage = string.Format("{0}", fileName); // At this point in the code, write the image to isolated storage.
사용자가 휴대폰 잠금 화면 설정 화면에서 앱을 기본 잠금 화면 배경 이미지 공급자로 설정하면 다음 이미지에 표시된 대로 앱 열기 버튼을 탭할 수 있습니다.

앱 열기 버튼을 탭하면 앱이 시작되고 QueryString에 정보가 표시됩니다. 최상의 사용자 환경을 위해 이 정보를 처리하도록 앱을 디자인해야 합니다. 예를 들어 사용자를 앱 내의 사용자 지정 잠금 화면 설정 화면으로 안내하거나 앱에서 이미지를 업데이트할 때 잠금 화면 배경 이미지가 업데이트되고 있다는 메시지를 표시할 수 있습니다.
다음 코드 예제에서는 OnNavigatedTo(NavigationEventArgs) 메서드에서 QueryString 정보를 확인하는 방법을 보여 줍니다.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); string lockscreenKey = "WallpaperSettings"; string lockscreenValue = "0"; bool lockscreenValueExists = NavigationContext.QueryString.TryGetValue(lockscreenKey, out lockscreenValue); if (lockscreenValueExists) { // Navigate the user to your app's lock screen settings screen here, // or indicate that the lock screen background image is updating. } }
앱 사용자를 위해 앱 내에서 휴대폰의 잠금 화면 설정 화면에 링크를 추가하는 것이 좋습니다. 그러면 앱 내에서 잠금 화면 배경 이미지 공급자로 앱을 프로그래밍 방식으로 끌 수 없기 때문에 사용자에게 유용합니다. 사용자가 휴대폰의 설정 화면으로 이동하여 직접 변경해야 합니다. 설정 화면에 링크를 추가하면 이 작업을 쉽고 간단하게 수행할 수 있습니다.
다음 코드 예제에서는 버튼 클릭을 휴대폰의 잠금 화면 설정 화면으로 라우팅하는 방법을 보여 줍니다.
private async void btnGoToLockSettings_Click(object sender, RoutedEventArgs e) { // Launch URI for the lock screen settings screen. var op = await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-lock:")); }