Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices.WindowsRuntime;
- using System.Timers;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.Foundation.Metadata;
- using Windows.System;
- using Windows.UI.Core;
- using Windows.UI.Notifications;
- using Windows.UI.Notifications.Management;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
- // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
- namespace TestingApp
- {
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- public sealed partial class Notification_Testing : Page
- {
- DispatcherTimer t;
- UserNotificationListener listener;
- private bool _waitingOrder;
- public bool WaitingOrder
- {
- get { return _waitingOrder; }
- set
- {
- if(value)
- {
- LaunchWebsite();
- }
- }
- }
- public Notification_Testing()
- {
- this.InitializeComponent();
- // Get the listener
- Load();
- t = new DispatcherTimer();
- t.Tick += T_Tick;
- t.Interval = new TimeSpan(0,0,0,0,500);
- t.Start();
- }
- private async void T_Tick(object sender, object e)
- {
- // Get the toast notifications
- IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
- foreach (UserNotification notif in notifs)
- {
- if (notif.AppInfo.AppUserModelId == "Chrome")
- {
- LaunchWebsite();
- listener.RemoveNotification(notif.Id);
- }
- }
- //listener.ClearNotifications();
- }
- public async void LaunchWebsite()
- {
- // The URI to launch
- var uriDigizani = new Uri(@"https://portal.digizani.com/portal/orders/unassigned");
- // Launch the URI
- var success = await Launcher.LaunchUriAsync(uriDigizani);
- }
- public async void Load()
- {
- listener = UserNotificationListener.Current;
- // And request access to the user's notifications (must be called from UI thread)
- UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();
- switch (accessStatus)
- {
- // This means the user has granted access.
- case UserNotificationListenerAccessStatus.Allowed:
- var x = "Works";
- // Yay! Proceed as normal
- break;
- // This means the user has denied access.
- // Any further calls to RequestAccessAsync will instantly
- // return Denied. The user must go to the Windows settings
- // and manually allow access.
- case UserNotificationListenerAccessStatus.Denied:
- // Show UI explaining that listener features will not
- // work until user allows access.
- break;
- // This means the user closed the prompt without
- // selecting either allow or deny. Further calls to
- // RequestAccessAsync will show the dialog again.
- case UserNotificationListenerAccessStatus.Unspecified:
- // Show UI that allows the user to bring up the prompt again
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement