锁屏图像在测试版应用程序中不会更改
本文关键字:应用程序 图像 测试版 | 更新日期: 2023-09-27 18:32:13
我在Windows Phone 8中创建了一个应用程序,该应用程序可以从后台任务更改锁屏图像。当运行代码时,该应用程序在模拟器和设备中运行良好。它包含launchforTest(),它使锁屏每30秒更改一次。
我收到一些评论,告诉 launchforTest() 在应用程序通过商店上传时不起作用。 它基本上是为了测试目的。
所以我的问题是,当我从我进行beta测试的商店安装我的应用程序时,后台任务不起作用,即锁屏图像不会改变
我在代码中缺少什么,使其无法正常工作,请帮助。
这是我的代码
私有资源密集型任务资源密集型任务; 私有字符串资源密集任务名称 = "智能锁屏计划任务代理"; 私有字符串资源密集任务说明 ="显示最新交易。
private StartTask()
{
LockScreenChange("ms-appdata:///Local/Image0.jpg", true);
}
private async void LockScreenChange(string filePathOfTheImage, bool isAppResource)
{
if (!LockScreenManager.IsProvidedByCurrentApplication)
{
// If you're not the provider, this call will prompt the user for permission.
// Calling RequestAccessAsync from a background agent is not allowed.
await LockScreenManager.RequestAccessAsync();
}
// Only do further work if the access is granted.
if (LockScreenManager.IsProvidedByCurrentApplication)
{
// 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(filePathOfTheImage, UriKind.Absolute);
// Set the lock screen background image.
LockScreen.SetImageUri(uri);
// Get the URI of the lock screen background image.
var currentImage = LockScreen.GetImageUri();
System.Diagnostics.Debug.WriteLine("The new lock screen background image is set to {0}", currentImage.ToString());
UpdatePrimaryTile();
StartResourceIntensiveAgent();// StartPeriodicAgent();//
// MessageBox.Show("Lock screen changed. Click F12 or go to lock screen.");
}
else
{
MessageBox.Show("Background can't be updated as you clicked no!!");
}
}
public void RemoveResourceIntensiveAgent()
{
try
{
if (resourceIntensiveTask != null)
{
ScheduledActionService.Remove(resourceIntensiveTaskName);
}
}
catch (Exception)
{
}
}
/// <summary>
/// Code to start the resource intensive task
/// </summary>
private void StartResourceIntensiveAgent()
{
// Variable for tracking enabled status of background agents for this app.
agentsAreEnabled = true;
resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask;
// If the task already exists and background agents are enabled for the
// application, you must remove the task and then add it again to update
// the schedule.
if (resourceIntensiveTask != null)
{
ScheduledActionService.Remove(resourceIntensiveTaskName);
}
resourceIntensiveTask = new ResourceIntensiveTask(resourceIntensiveTaskName);
// The description is required for periodic agents. This is the string that the user
// will see in the background services Settings page on the device.
resourceIntensiveTask.Description = (resourceIntensiveTaskDescription);
// Place the call to Add in a try block in case the user has disabled agents.
try
{
ScheduledActionService.Add(resourceIntensiveTask);
//ResourceIntensiveStackPanel.DataContext = resourceIntensiveTask;
resourceIntensiveTask.ExpirationTime = DateTime.Now.AddDays(14);
// If debugging is enabled, use LaunchForTest to launch the agent in one minute.
ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(30));
}
catch (InvalidOperationException exception)
{
if (exception.Message.Contains("BNS Error: The action is disabled"))
{
MessageBox.Show("Background agents for this application have been disabled by the user.");
agentsAreEnabled = false;
}
}
catch (SchedulerServiceException)
{
// No user action required.
}
}
您的问题是您已将后台代理实现为ResourceIntensiveTask
。资源密集型任务在以下非常具体的约束下运行:
- 电话已接通电源
- 锁定屏幕已启用 无线网络
- (非蜂窝)连接可用
请考虑将此后台代理实现为定期任务。如果遇到运行时约束,请考虑重构尽可能多的代码,以便在主应用程序运行时尽可能预处理锁屏界面图像的哪些部分,或者通过在包中创建可用于传达相同信息的静态图像资产。
参考:Windows Phone 的后台代理:资源密集型代理的约束