Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Runtime.InteropServices.WindowsRuntime;
  7. using System.Timers;
  8. using Windows.Foundation;
  9. using Windows.Foundation.Collections;
  10. using Windows.Foundation.Metadata;
  11. using Windows.System;
  12. using Windows.UI.Core;
  13. using Windows.UI.Notifications;
  14. using Windows.UI.Notifications.Management;
  15. using Windows.UI.Xaml;
  16. using Windows.UI.Xaml.Controls;
  17. using Windows.UI.Xaml.Controls.Primitives;
  18. using Windows.UI.Xaml.Data;
  19. using Windows.UI.Xaml.Input;
  20. using Windows.UI.Xaml.Media;
  21. using Windows.UI.Xaml.Navigation;
  22.  
  23. // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
  24.  
  25. namespace TestingApp
  26. {
  27. /// <summary>
  28. /// An empty page that can be used on its own or navigated to within a Frame.
  29. /// </summary>
  30. public sealed partial class Notification_Testing : Page
  31. {
  32. DispatcherTimer t;
  33. UserNotificationListener listener;
  34.  
  35. private bool _waitingOrder;
  36. public bool WaitingOrder
  37. {
  38. get { return _waitingOrder; }
  39. set
  40. {
  41. if(value)
  42. {
  43. LaunchWebsite();
  44. }
  45.  
  46. }
  47. }
  48.  
  49.  
  50. public Notification_Testing()
  51. {
  52. this.InitializeComponent();
  53. // Get the listener
  54. Load();
  55. t = new DispatcherTimer();
  56. t.Tick += T_Tick;
  57. t.Interval = new TimeSpan(0,0,0,0,500);
  58. t.Start();
  59. }
  60.  
  61. private async void T_Tick(object sender, object e)
  62. {
  63. // Get the toast notifications
  64. IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
  65.  
  66. foreach (UserNotification notif in notifs)
  67. {
  68. if (notif.AppInfo.AppUserModelId == "Chrome")
  69. {
  70. LaunchWebsite();
  71. listener.RemoveNotification(notif.Id);
  72. }
  73. }
  74.  
  75. //listener.ClearNotifications();
  76. }
  77.  
  78.  
  79. public async void LaunchWebsite()
  80. {
  81.  
  82. // The URI to launch
  83. var uriDigizani = new Uri(@"https://portal.digizani.com/portal/orders/unassigned");
  84.  
  85. // Launch the URI
  86. var success = await Launcher.LaunchUriAsync(uriDigizani);
  87. }
  88.  
  89. public async void Load()
  90. {
  91. listener = UserNotificationListener.Current;
  92.  
  93. // And request access to the user's notifications (must be called from UI thread)
  94. UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();
  95.  
  96. switch (accessStatus)
  97. {
  98. // This means the user has granted access.
  99. case UserNotificationListenerAccessStatus.Allowed:
  100. var x = "Works";
  101. // Yay! Proceed as normal
  102. break;
  103.  
  104. // This means the user has denied access.
  105. // Any further calls to RequestAccessAsync will instantly
  106. // return Denied. The user must go to the Windows settings
  107. // and manually allow access.
  108. case UserNotificationListenerAccessStatus.Denied:
  109.  
  110. // Show UI explaining that listener features will not
  111. // work until user allows access.
  112. break;
  113.  
  114. // This means the user closed the prompt without
  115. // selecting either allow or deny. Further calls to
  116. // RequestAccessAsync will show the dialog again.
  117. case UserNotificationListenerAccessStatus.Unspecified:
  118.  
  119. // Show UI that allows the user to bring up the prompt again
  120. break;
  121. }
  122. }
  123.  
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement