- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试在 WP8.1 (WinRT) 中发生地理围栏事件(进入/退出)时触发 BackgroundTask。我已经编写了一个示例应用程序来尝试让它工作,但似乎无法做到这一点。
到目前为止,这些是我尝试让 Geofences 在后台运行所采取的步骤:
LocationTrigger(LocationTriggerType.Geofence);
我在我的 app.manifest 中启用了:
BackgroundTask.GeofenceBackgroundTask
我的后台任务位于一个名为 BackgroundTask
的单独项目中。它是一个 WindowsRT 组件,包含一个类 GeofenceBackgroundTask
。
可以在这个[链接]( https://github.com/kiangtengl/GeofenceSample ) 找到该项目的代码:
在模拟器中运行代码
将位置设置为:纬度 = 01.3369,经度 = 103.7364
点击注册地理围栏 + BackgroundTasks 按钮
退出应用(按主页按钮)
将当前位置更改为距您先前设置的位置 100 米的任何位置。应该会弹出一条通知。
public static async Task GetLocationCapabilities()
{
try
{
var geolocator = new Geolocator();
await geolocator.GetGeopositionAsync();
var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
Debug.WriteLine("background access status" + backgroundAccessStatus);
}
catch (UnauthorizedAccessException e)
{
Debug.WriteLine(e);
}
catch (TaskCanceledException e)
{
Debug.WriteLine(e);
}
}
public static void CreateGeofence(BasicGeoposition position, double radius, string id = "default")
{
// The Geofence is a circular area centered at (latitude, longitude) point, with the
// radius in meter.
var geocircle = new Geocircle(position, radius);
// Sets the events that we want to handle: in this case, the entrace and the exit
// from an area of intereset.
var mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited;
// Specifies for how much time the user must have entered/exited the area before
// receiving the notification.
var dwellTime = TimeSpan.FromSeconds(1);
// Creates the Geofence and adds it to the GeofenceMonitor.
var geofence = new Geofence(id, geocircle, mask, false, dwellTime);
try
{
GeofenceMonitor.Current.Geofences.Add(geofence);
}
catch (Exception e)
{
Debug.WriteLine(e);
// geofence already added to system
}
}
public static async Task RegisterBackgroundTask()
{
try
{
// Create a new background task builder
var geofenceTaskBuilder = new BackgroundTaskBuilder()
{
Name = GeofenceBackgroundTaskName,
TaskEntryPoint = "BackgroundTask.GeofenceBackgroundTask"
};
// Create a new location trigger
var trigger = new LocationTrigger(LocationTriggerType.Geofence);
// Associate the location trigger with the background task builder
geofenceTaskBuilder.SetTrigger(trigger);
var geofenceTask = geofenceTaskBuilder.Register();
// Associate an event handler with the new background task
geofenceTask.Completed += (sender, e) =>
{
try
{
e.CheckResult();
}
catch(Exception error)
{
Debug.WriteLine(error);
}
};
}
catch(Exception e)
{
// Background task probably exists
Debug.WriteLine(e);
}
}
namespace BackgroundTask
{
public sealed class GeofenceBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
var toastTemplate = ToastTemplateType.ToastText02;
var toastXML = ToastNotificationManager.GetTemplateContent(toastTemplate);
var textElements = toastXML.GetElementsByTagName("text");
textElements[0].AppendChild(toastXML.CreateTextNode("You have left!"));
var toast = new ToastNotification(toastXML);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
}
}
最佳答案
我发现上面的代码示例以及上面的代码都有效。我遇到的问题是 Windows Phone 8.1 不会自动触发地理围栏事件。在触发 BackgroundTask 之前,您必须等待一定时间 <5 分钟。
这也适用于前景中的地理围栏。
关于windows - 后台 Windows Phone 8.1 (WinRT) 中的地理围栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23608073/
是否可以在 WinRT 中实现自定义转换?例如。如果能够实现控件可见性的转换,那就太好了。因此,当您显示/隐藏分割 View 的一部分时,它会使用滑动效果为整个 View 添加动画效果。 最佳答案 是
我正在开发基于 XAML C# 的通用应用程序(目前专注于 WP8.1) 我的应用程序的主页非常复杂,有 3 个枢轴,每个枢轴都有网格、图像、边框、按钮、 ListView 等 问题有时是当我在执行其
我不久前从 C++/CX 切换到 C++/winrt,目前我被卡住了,因为我想创建一个单例 winrt 类。我阅读了有关 winrt::static_lifetime ( https://learn.
与 C++/CX 不同,C++/WinRT 中似乎没有 GUID 的包装器类型。它只使用普通的 C GUID struct原样。因此构造初始化 GUID 的唯一方法是使用 aggregate init
文档显示了这个 C# 片段: async void DisplayDeleteFileDialog(){ ContentDialog deleteFileDialog = new Conten
文档显示了这个 C# 片段: async void DisplayDeleteFileDialog(){ ContentDialog deleteFileDialog = new Conten
这是 xaml 的样子:
我有一个文本框,我不希望用户粘贴到其中。 如何防止粘贴? 从另一个应用程序中将文本拖放到 TextBox 中也是一个粘贴事件吗? 最佳答案 从 Windows 8.1 开始,Windows.UI.XA
这实际上更像是一个好奇心类型的问题。我负责跨程序集和原始 IL 查找类型。不过,Windows 8 确实让我正在实现的某些事情陷入困境。我发现 WinRT 和非 WinRT 框架程序集共享相同的完全限
我正在尝试创建一个条目页面,其中一个选项是选择一个项目。该列表可以超过 1000 个,并且显示列出项目的启用搜索的页面是有意义的。当用户从编辑/创建屏幕中单击“选择项目”时,我可以将导航参数传递到该屏
我正在将我的库移植到 WinRT,它依赖于 System.Globalization.Calendar 类及其派生类,如 GregorianCalendar 和 HijriCalendar 等。虽然这
我需要下载一个大的视频文件并将其保存到硬盘上。 然后我需要使用 XAML 媒体元素播放这个视频文件。 但该文件必须使用 AES 256 算法和加密 key 进行加密。任何时候都不得将未加密的数据写入硬
假设我有这样的事情: 像这样: public class MyViewModel : INotifyPropertyChanged { public MyViewModel() {
我正在尝试使用 WinRT 中的当前文化来格式化日期时间值。但是CurrentCulture 属性似乎并不尊重系统文化。 我尝试了以下两个属性, System.Globalization.Cultur
我的应用程序是在 silverlight 中开发的。计划在今年晚些时候推出。我担心我的 xaps 会被逆向工程。我的 wcf 服务确实有很多智能,但您不能将所有内容都放在服务中。现在 winrt 是另
我使用下面的代码发送电子邮件。但是当我在 VS 的模拟器中运行它时,无法启动电子邮件客户端。我做错了什么?但是电子邮件客户端以本地计算机模式启动。 var mailto = new Uri("mail
我正在开发通用应用程序。在为Windows Phone 8.1项目设计 View 时,不能使任何按钮的宽度小于109。如果将按钮的width属性设置为小于该宽度,则呈现时它将变为109。 我想知道如何
情况: 我从不同的互联网位置获取 json 对象。 这些包含我放在 BingMap 上的许多地理坐标。效果非常好。 问题: 但是当我从互联网位置获取数据时,我得到了一个阻塞的用户界面。有没有办法在后台
想法是这样的,您正在 Visual Studio 2013 Update 2 中为 Windows 8.1-Update 和 Windows Phone 8.1 创建一个 WinRT-XAML 通用应
什么是更新(替换)本地存储中的图像的好方法,该图像绑定(bind)到导航堆栈中的图像控件。 更具体地说:我在页面 A (ViewProfile.xaml) 中显示图像,图像源绑定(bind)到属性 I
我是一名优秀的程序员,十分优秀!