修改锁屏背景代码
这里我解释一下 "ms-appx:///" 和 "ms-appdata:///Local/"
ms-appdata points to the root of the local app data folder.也就是说当你的图片文件是在文件系统中的时候使用ms-appdata前缀,时常从网络下载的图片保存在隔离存储器中就要使用这个前缀了。
ms-appx points to the Local app install folder, to reference resources bundled in the XAP package. 当此张图片是和当前应用一起打包在XAP包中的时候使用ms-appx前缀。
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());
}
}
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.
当然在运行程序之前我们不能用代码干预设置锁屏背景在我们的程序中可以先预设一张图片作为锁屏背景 但是这张图片的命名必须是 DefaultLockScreen.jpg且将这张图片放置在项目根目录下.
同时在锁屏设置页面我们可以看到 open app的按钮可以直接导航到我们的应用中去 这里处理这个导航的方法和App to App 的方法类似 重载在App中处理InitializePhoneApplication方法 UriMapperBase即可 相信参考 windows phone 8 中的应用间通信
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:"));
}
2. 锁屏通知
windows phone 7 中已经包含了推送通知,在windows phone 8中开发者可以将其融入到锁屏界面中来
下图还是一张选自MSDN的截图很清晰的说明通知的情况,左侧大字是显示的应用的详细状态,下面一行可以显示5个应用程序的通知数量。
同样在锁屏设置中可以选择设置显示通知的应用及显示即时状态的应用。
下面介绍下应用如何实现这个通知
首先第一步还是要在WMAppManifest中声明我们的应用是一个支持锁屏通知的应用同时指定通知的图标来源。
图标必须是一个白色背景透明 38 x 38 像素的PNG 图片。
在Token节点中