Notification Toast and Geofence Windows Phone 8.1

I am having a strange problem with my Windows Phone 8.1 application. The app will send a toast notification every time a user is near their point of interest using Geofence Quick Start: setting up a geoforum and BackgroundTask Quick Start: listening to geophony events in the background

And this is a background task (example)

public void Run(IBackgroundTaskInstance taskInstance)
{
    // Get the information of the geofence(s) that have been hit
    var reports = GeofenceMonitor.Current.ReadReports();
    var report = reports.FirstOrDefault(r => (r.Geofence.Id == "id") && (r.NewState == GeofenceState.Entered));

    if (report == null) return;

    // Create a toast notification to show a geofence has been hit
    var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

    var txtNodes = toastXmlContent.GetElementsByTagName("text");
    txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Geofence triggered toast!"));
    txtNodes[1].AppendChild(toastXmlContent.CreateTextNode(report.Geofence.Id));

    var toast = new ToastNotification(toastXmlContent);
    var toastNotifier = ToastNotificationManager.CreateToastNotifier();
    toastNotifier.Show(toast);

}

, VS, , Toast , ... Windows Phone, , . , Geofence BackgroundTask ( , , , : s)... - .

, " + ", Package.appxmanifest Toast Capable: YES.

- , ?

+4
1

, , . , , , .

+1

Source: https://habr.com/ru/post/1546062/


All Articles