コード例 #1
0
        public async Task <bool> RequestNotificationListenerAccess()
        {
            // Check whether the listener is supported
            if (ApiInformation.IsTypePresent("Windows.UI.Notifications.Management.UserNotificationListener"))
            {
                try
                {
                    // request access to the user's notifications (must be called from UI thread) or
                    // just turn Notifications On at Windows Apps & Features -> Listener -> App Permissions
                    UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();

                    if (accessStatus != UserNotificationListenerAccessStatus.Allowed)
                    {
                        ConsoleProxy.WriteLine(null, ConsoleColor.DarkRed, "Notification listener access isn't allowed in Windows settings");
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    ConsoleProxy.WriteLine(null, ConsoleColor.DarkRed, e.Message);
                }

                return(true);
            }
            else
            {
                ConsoleProxy.WriteLine(null, ConsoleColor.DarkRed, "The Windows version is not compatible - Notification Listener is not exists");
            }

            return(false);
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: Anushiravani/Minista
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            CreateConfig();


            var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;

            coreTitleBar.ExtendViewIntoTitleBar = true;
            //AppTitleBar.Height = coreTitleBar.Height;
            coreTitleBar.LayoutMetricsChanged += CoreTitleBarLayoutMetricsChanged;
            // Set XAML element as a draggable region.
            //AppTitleBar.Height = coreTitleBar.Height;

            UpdateTitleBarLayout(coreTitleBar);
            Window.Current.SetTitleBar(AppTitleBarORG);
            if (InstaApi == null || InstaApi != null && !InstaApi.IsUserAuthenticated)
            {
                SetStackPanelTitleVisibility(Visibility.Collapsed);
                NavigationService.Navigate(typeof(Views.Sign.SignInView));
            }
            else
            {
                NavigateToMainView();
            }

            if (!SettingsHelper.Settings.AskedAboutPosition)
            {
                SettingsGrid.Visibility = Visibility.Visible;
            }
            if (ScreenOnRequest != null)
            {
                ScreenOnRequest.RequestActive();
            }
            CheckLicense();
            try
            {
                if (Passcode.IsEnabled)
                {
                    PassCodeView.Visibility = Visibility.Visible;
                    LockControl.Visibility  = Visibility.Visible;
                }
                else
                {
                    PassCodeView.Visibility = Visibility.Collapsed;
                    LockControl.Visibility  = Visibility.Collapsed;
                }
            }
            catch { }
            try
            {
                await BackgroundExecutionManager.RequestAccessAsync();
            }
            catch { }
            try
            {
                UserNotificationListener listener = UserNotificationListener.Current;
                await listener.RequestAccessAsync();
            }
            catch { }
        }
コード例 #3
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            UserNotificationListener             c = UserNotificationListener.Current;
            UserNotificationListenerAccessStatus x = await c.RequestAccessAsync();

            var toast = await c.GetNotificationsAsync(Windows.UI.Notifications.NotificationKinds.Toast);

            foreach (var notif in toast)
            {
                var           notification  = notif.Notification;
                StringBuilder stringBuilder = new StringBuilder();
                var           appname       = notif.AppInfo.DisplayInfo.DisplayName;
                if (appname != "Mail")
                {
                    continue;
                }
                foreach (NotificationBinding binding in notification.Visual.Bindings)
                {
                    foreach (var textElelment in binding.GetTextElements())
                    {
                        stringBuilder.Append(textElelment.Text);
                        stringBuilder.Append("\n");
                    }
                    ContentDialog mydialog = new ContentDialog
                    {
                        Title           = appname,
                        Content         = stringBuilder.ToString(),
                        CloseButtonText = "ok"
                    };
                    ContentDialogResult contentDialogResult = await mydialog.ShowAsync();
                }
            }
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: PavelSHK/Notify
        public async void SetListener()
        {
            listener = UserNotificationListener.Current;

            UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();

            switch (accessStatus)
            {
            case UserNotificationListenerAccessStatus.Allowed:
                GetAccessBackgroundTask();
                Debug.WriteLine("Уведомления доступны");

                break;

            case UserNotificationListenerAccessStatus.Denied:
                StatusUpdate("Уведомления недоступны. Откройте");
                break;

            case UserNotificationListenerAccessStatus.Unspecified:
                Debug.WriteLine("Неизвестно");
                break;

            default:
                Status.Text = "Уведомления недоступны";
                break;
            }
        }
コード例 #5
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // go to loading page
            Navigation.IsEnabled = false;
            _ = ContentFrame.Navigate(typeof(Pages.LoadingPage), null);
            // check permissions
            try
            {
                Conf.Log("detecting permissions...");
                var accessStatus = await Listener.RequestAccessAsync();

                switch (accessStatus)
                {
                case UserNotificationListenerAccessStatus.Allowed:
                    Conf.Log("permission granted!", LogLevel.Complete);
                    IsListenerActive    = true;
                    IsPermissionGranted = true;
                    var initialList = await Listener.GetNotificationsAsync(NotificationKinds.Toast);

                    Conf.Log($"loading {initialList.Count} notification(s)...");
                    foreach (var notif in initialList)
                    {
                        Conf.CurrentConf.AddApp(new AppInfo(notif.AppInfo)
                        {
                            ForwardingEnabled = !Conf.CurrentConf.MuteNewApps
                        });
                    }
                    Notifications.AddRange(initialList);
                    Listener.NotificationChanged += NotificationHandler;
                    Conf.Log("notification listener activated.", LogLevel.Complete);
                    StartUploadWorker();
                    break;

                default:
                    Conf.Log("permission not granted, no exceptions thrown.", LogLevel.Warning);
                    await NoPermissionDialog();

                    break;
                }
            }
            catch (Exception ex)
            {
                Conf.Log($"notification listener failed: {ex.Message}, HRESULT 0x{ex.HResult:x}", LogLevel.Error);
                await NoPermissionDialog(ex.Message);
            }
            Navigation.SelectedItem = HomePageItem;
            Navigation.IsEnabled    = true;
            // wait 1 sec
            var paneCloser = new Thread(async() =>
            {
                Thread.Sleep(1000);
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Navigation.IsPaneOpen = false;
                });
            });

            paneCloser.Start();
        }
コード例 #6
0
        public static bool RequestAccess(out bool denied)
        {
            bool ret = false;

            denied = false;

            // Get the listener
            UserNotificationListener listener = UserNotificationListener.Current;

            // And request access to the user's notifications (must be called from UI thread)
            var t = listener.RequestAccessAsync();

            UserNotificationListenerAccessStatus accessStatus;

            try
            {
                while (t.Status != AsyncStatus.Completed)
                {
                    Thread.Sleep(10);
                }
                accessStatus = t.GetResults();
            }
            finally
            {
                t.Close();
            }

            switch (accessStatus)
            {
            // This means the user has granted access.
            case UserNotificationListenerAccessStatus.Allowed:

                // Yay! Proceed as normal
                ret = true;
                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.
                denied = true;
                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;
            }

            return(ret);
        }
コード例 #7
0
        private static async Task NowTask()
        {
            UserNotificationListener             listener     = UserNotificationListener.Current;
            UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();

            switch (accessStatus)
            {
            case UserNotificationListenerAccessStatus.Allowed:
                Console.WriteLine("notifications allowed");
                break;

            case UserNotificationListenerAccessStatus.Denied:
                Console.WriteLine("notifications denied");
                break;

            case UserNotificationListenerAccessStatus.Unspecified:
                Console.WriteLine("notifications something else");
                break;
            }
            IReadOnlyList <UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);

            List <string> combined = new List <string>();

            foreach (var notif in notifs)
            {
                NotificationBinding toastBinding = notif.Notification.Visual.GetBinding(KnownNotificationBindings.ToastGeneric);
                if (toastBinding != null)
                {
                    // And then get the text elements from the toast binding
                    IReadOnlyList <AdaptiveNotificationText> textElements = toastBinding.GetTextElements();

                    // Treat the first text element as the title text
                    string titleText = textElements.FirstOrDefault()?.Text;

                    // We'll treat all subsequent text elements as body text,
                    // joining them together via newlines.
                    string bodyText = string.Join("\n", textElements.Skip(1).Select(t => t.Text));
                    //Console.WriteLine("\nhead: " + titleText);
                    //Console.WriteLine("body: " + bodyText);

                    combined.Add(titleText);
                    combined.Add(bodyText);
                }
            }

            Console.WriteLine("\nWritten to: " + Settings.notificationCacheFileLocation);
            await File.WriteAllLinesAsync(Settings.notificationCacheFileLocation, combined);

            //clears windows messages | throws an AggregateException, I have no idea why, nothing from google, too
            //listener.ClearNotifications();
            Environment.Exit(0);
        }
コード例 #8
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            Debug.Write("button pressed");
            MediaElement mediaElement = new MediaElement();

            // Get the listener

            UserNotificationListenerAccessStatus accessStatus =
                await listener.RequestAccessAsync();

            if (accessStatus != UserNotificationListenerAccessStatus.Allowed)
            {
                return;
            }

            // Get the toast notifications
            NotificationsProcessor.GetNotificationsAndProcessThem();
            //Request / check background task access via BackgroundExecutionManager.RequestAccessAsync
            var requestStatus =
                await Windows.ApplicationModel.Background.BackgroundExecutionManager.RequestAccessAsync();

            if (requestStatus != BackgroundAccessStatus.AlwaysAllowed)
            {
            }


            ApplicationData.Current.LocalSettings.Values["python"]  = this.PythonPath.Text;
            ApplicationData.Current.LocalSettings.Values["command"] = this.NotificationPath.Text;
            // If background task isn't registered yet
            if (!BackgroundTaskRegistration.AllTasks.
                Any(i => i.Value.Name.Equals("UserNotificationChanged")))
            {
                // Specify the background task
                var builder = new BackgroundTaskBuilder()
                {
                    Name = "UserNotificationChanged"
                };

                // Set the trigger for Listener, listening to Toast Notifications
                builder.SetTrigger(new UserNotificationChangedTrigger(NotificationKinds.Toast));

                // Register the task
                builder.Register();
            }
            button.IsEnabled = false;
            Python.IsEnabled = false;
            NotificationPythonFile.IsEnabled = false;
        }
コード例 #9
0
        private async void Show_Dialog_Messages()
        {
            headers.Text = "";
            UserNotificationListener             c = UserNotificationListener.Current;
            UserNotificationListenerAccessStatus x = await c.RequestAccessAsync();

            int i     = 100;
            var toast = await c.GetNotificationsAsync(Windows.UI.Notifications.NotificationKinds.Toast);

            foreach (var notif in toast)
            {
                var           notification  = notif.Notification;
                StringBuilder stringBuilder = new StringBuilder();
                var           appname       = notif.AppInfo.DisplayInfo.DisplayName;
                if (appname != "Mail")
                {
                    continue;
                }
                foreach (NotificationBinding binding in notification.Visual.Bindings)
                {
                    foreach (var textElelment in binding.GetTextElements())
                    {
                        stringBuilder.Append(textElelment.Text);
                        stringBuilder.Append("\n");
                    }
                    SendToast(appname + "\n" + stringBuilder.ToString(), i.ToString());
                    headers.Text = headers.Text + "\n" + stringBuilder.ToString();
                    //ContentDialog mydialog = new ContentDialog
                    //{
                    //    Title = appname,
                    //    Content = stringBuilder.ToString(),
                    //    CloseButtonText = "ok"
                    //};
                    //try
                    //{
                    //    ContentDialogResult contentDialogResult = await mydialog.ShowAsync();
                    //}
                    //catch (System.Runtime.InteropServices.COMException e)
                    //{
                    //    SendToast(
                    //    e.Message);
                    //}

                    i = i + 1;
                }
            }
        }
コード例 #10
0
        public static async Task <bool> RequestAccessAsync()
        {
            var status = UserNotificationListenerAccessStatus.Unspecified;

            if (ApiHelper.IsMobileSystem())
            {
                status = UserNotificationListener.GetAccessStatus();
                if (status == UserNotificationListenerAccessStatus.Allowed)
                {
                    return(true);
                }
            }

            status = await UserNotificationListener.RequestAccessAsync();

            return(status == UserNotificationListenerAccessStatus.Allowed);
        }
コード例 #11
0
        private async void Form1_LoadAsync(object sender, EventArgs e)
        {
            if (ApiInformation.IsTypePresent("Windows.UI.Notifications.Management.UserNotificationListener"))
            {
                // Listener supported!
            }

            else
            {
                // Older version of Windows, no Listener
            }
            // Get the listener
            UserNotificationListener 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:

                // 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;
            }
            IReadOnlyList <UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
        }
コード例 #12
0
        public async void SetListener()
        {
            listener = UserNotificationListener.Current;

            UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();

            switch (accessStatus)
            {
            case UserNotificationListenerAccessStatus.Allowed:
                Debug.WriteLine("Уведомления доступны");
                break;

            case UserNotificationListenerAccessStatus.Denied:
                Debug.WriteLine("Уведомления недоступны");
                break;

            case UserNotificationListenerAccessStatus.Unspecified:
                Debug.WriteLine("Неизвестно");
                break;
            }
        }
コード例 #13
0
        public async void CheckNotificationAccess()
        {
            // Get the listener
            UserNotificationListener 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:
                // Yay! Proceed as normal
                isAccessGranted = true;
                // Subscribe to foreground event
                listener.NotificationChanged += Listener_NotificationChanged;
                // Get the toast notifications
                //IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
                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;
            }
        }
コード例 #14
0
ファイル: WidgetPhone.xaml.cs プロジェクト: lulzzz/Miriot
        private async Task <bool> AskRequest()
        {
            // Get the listener
            UserNotificationListener 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:
                return(true);

                // 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;
            }

            return(false);
        }
コード例 #15
0
        public static async Task <bool> GetNotificationPermission()
        {
            UserNotificationListener             listener     = UserNotificationListener.Current;
            UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();

            switch (accessStatus)
            {
            case UserNotificationListenerAccessStatus.Allowed:
                Debug.WriteLine("Notification Access ALLOWED!");
                return(true);

            case UserNotificationListenerAccessStatus.Denied:
                Debug.WriteLine("Notification Access DENIED!");
                return(false);

            case UserNotificationListenerAccessStatus.Unspecified:
                Debug.WriteLine("Notification Access UNSPECIFIED!");
                return(false);

            default:
                Debug.WriteLine("This shouldn't be happening!");
                return(false);
            }
        }
コード例 #16
0
        private async Task UpdateNotiFile()
        {
            // Check Permissions
            if (!ApiInformation.IsTypePresent("Windows.UI.Notifications.Management.UserNotificationListener"))
            {
                Debug.WriteLine("IsTypePresent: NG");
                return;
            }
            Debug.WriteLine("IsTypePresent: OK");

            UserNotificationListener listener = UserNotificationListener.Current;

            Debug.Write("listener: ");
            Debug.WriteLine(listener);

            while (true)
            {
                // Read Notifications
                try
                {
                    UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();

                    Debug.Write("accessStatus: ");
                    Debug.WriteLine(accessStatus);

                    if (accessStatus != UserNotificationListenerAccessStatus.Allowed)
                    {
                        Debug.WriteLine("アクセス拒否");
                        return;
                    }
                    Debug.WriteLine("アクセス許可");

                    IReadOnlyList <UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);

                    // Write to Download/App3

                    Windows.Storage.StorageFile file = await DownloadsFolder.CreateFileAsync("notifications.txt");

                    // await Windows.Storage.FileIO.WriteTextAsync(file, "Example of writing a string\r\n");

                    // Append a list of strings, one per line, to the file
                    var listOfStrings = new List <string> {
                    };

                    foreach (var n in notifs)
                    {
                        NotificationBinding toastBinding = n.Notification.Visual.GetBinding(KnownNotificationBindings.ToastGeneric);

                        if (toastBinding != null)
                        {
                            IReadOnlyList <AdaptiveNotificationText> textElements = toastBinding.GetTextElements();

                            string titleText = textElements.FirstOrDefault()?.Text;

                            string bodyText = string.Join("\n", textElements.Skip(1).Select(t => t.Text));

                            Debug.Write("Title:");
                            Debug.WriteLine(titleText);
                            Debug.Write("Body:");
                            Debug.WriteLine(bodyText);

                            int MsgType = GetNotiType(n.AppInfo.DisplayInfo.DisplayName);
                            if (MsgType != -1)
                            {
                                listOfStrings.Add(String.Format("{0}", MsgType));
                            }
                            // await Windows.Storage.FileIO.WriteTextAsync(file, String.Format("{0}, {1}\n", n.AppInfo.DisplayInfo.DisplayName, titleText));
                        }
                    }
                    await Windows.Storage.FileIO.AppendLinesAsync(file, listOfStrings); // each entry in the list is written to the file on its own line.

                    await Task.Delay(TimeSpan.FromSeconds(1));
                }
                catch (Exception ex)
                {
                }
            }
        }
コード例 #17
0
        private async void SyncNotifications()
        {
            // Get the listener
            UserNotificationListener listener = UserNotificationListener.Current;

            // And request access to the user's notifications (must be called from UI thread)
            UserNotificationListenerAccessStatus notificationListenerAccessStatus = await listener.RequestAccessAsync();

            switch (notificationListenerAccessStatus)
            {
            // This means the user has granted access.
            case UserNotificationListenerAccessStatus.Allowed:
                // Get the toast notifications
                notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);

                Debug.WriteLine("Size of current notification buffer: " + notifs.Count());
                AcHelper.ProcessNotification(notifs.LastOrDefault());
                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:
                Debug.WriteLine("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:
                Debug.WriteLine("UserNotificationListenerAccessStatus.Unspecified");
                // Show UI that allows the user to bring up the prompt again
                break;
            }
        }
コード例 #18
0
        public static async void RegisterBackgroundTask()
        {
            // TODO: Request/check Listener access via UserNotificationListener.Current.RequestAccessAsync

            // Get the listener
            UserNotificationListener 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:

                // 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.
                ContentDialog diniedDialog = new ContentDialog()
                {
                    Title           = "Access denied",
                    Content         = "Access request is denied. Go to Windows Settings and allow access manually.",
                    CloseButtonText = "Ok"
                };
                await diniedDialog.ShowAsync();

                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;
            }

            // TODO: request / check background task access via backgroundexecutionmanager.requestaccessasync
            // https://docs.microsoft.com/en-us/windows/uwp/launch-resume/run-a-background-task-on-a-timer-
            var requeststatus = await BackgroundExecutionManager.RequestAccessAsync();

            if (requeststatus != BackgroundAccessStatus.AlwaysAllowed)
            {
                // depending on the value of requeststatus, provide an appropriate response
                // such as notifying the user which functionality won't work as expected
                ContentDialog deniedDialog = new ContentDialog()
                {
                    Title             = "Notice",
                    Content           = "Background access is not \"Always allowed\". Go to Windows Settings and allow access manually.",
                    PrimaryButtonText = "Go to Settings",
                    CloseButtonText   = "Back"
                };
                deniedDialog.PrimaryButtonClick += async(s, a) =>
                {
                    var success = await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:batterysaver-usagedetails"));
                };
                await deniedDialog.ShowAsync();
            }

            // If background task isn't registered yet
            if (!BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals("UserNotificationChanged")))
            {
                // Specify the background task
                var builder = new BackgroundTaskBuilder()
                {
                    Name = "UserNotificationChanged"
                };

                // Set the trigger for Listener, listening to Toast Notifications
                builder.SetTrigger(new UserNotificationChangedTrigger(NotificationKinds.Toast));

                // Register the task
                builder.Register();
            }
        }
コード例 #19
0
        private async void Initialize()
        {
            try
            {
                BackgroundTaskHelper.RegisterIfNotRegistered();
            }

            catch (Exception ex)
            {
                Error = "Failed to register background task: " + ex.ToString();
                return;
            }

            var picLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);

            string        path   = picLibrary.SaveFolder.Path;
            string        name   = "ZLog.csv";
            StorageFolder folder = KnownFolders.PicturesLibrary;
            var           tRes   = folder.TryGetItemAsync(name);
            await Task.Delay(1000);

            var outputFile = tRes.GetResults();

            if (outputFile is null == false)
            {
                StorageFolder storage  = KnownFolders.PicturesLibrary;
                StorageFile   zlogFile = await storage.GetFileAsync(name);

                await zlogFile.DeleteAsync();

                await Task.Delay(1000);

                await storage.CreateFileAsync(name, CreationCollisionOption.OpenIfExists);

                await Task.Delay(1000);
            }



            try
            {
                _listener = UserNotificationListener.Current;

                // Check listener status
                var accessStatus = await _listener.RequestAccessAsync();

                switch (accessStatus)
                {
                case UserNotificationListenerAccessStatus.Allowed:
                    // Good, continue through
                    break;

                case UserNotificationListenerAccessStatus.Denied:
                    Error = "Listener permission has been denied. Please go to your settings and allow listener access for this app, then close and re-launch this app.";
                    return;

                default:
                    Error = "Please close and re-open this app. Listener permission hasn't been allowed or denied yet.";
                    return;
                }
            }

            catch (Exception ex)
            {
                Error = "Failed requesting access to Listener: " + ex.ToString();
                return;
            }

            UpdateNotifications();
        }
コード例 #20
0
ファイル: MainPage.xaml.cs プロジェクト: ramtinak/Minista
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            ThemeHelper.InitTheme(SettingsHelper.Settings.CurrentTheme);
            CreateConfig();
            try
            {
                Focus(FocusState.Pointer);
            }
            catch { }
            var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;

            coreTitleBar.ExtendViewIntoTitleBar = true;
            coreTitleBar.LayoutMetricsChanged  += CoreTitleBarLayoutMetricsChanged;
            UpdateTitleBarLayout(coreTitleBar);
            Window.Current.SetTitleBar(AppTitleBarORG);
            if (InstaApi == null || InstaApi != null && !InstaApi.IsUserAuthenticated)
            {
                SetStackPanelTitleVisibility(Visibility.Collapsed);
                NavigationService.Navigate(typeof(Views.Sign.SignInView));
            }
            else
            {
                NavigateToMainView();
            }

            if (!SettingsHelper.Settings.AskedAboutPosition)
            {
                SettingsGrid.Visibility = Visibility.Visible;
            }
            //if (App.ScreenOnRequest != null)
            //    App.ScreenOnRequest.RequestActive();
            CheckLicense();


            var ver = await IsUsingLatestVersion();

            var aaaabc = await GetLatestVersionNumber();

            try
            {
                if (Passcode.IsEnabled)
                {
                    PassCodeView.Visibility = Visibility.Visible;
                    LockControl.Visibility  = Visibility.Visible;
                }
                else
                {
                    PassCodeView.Visibility = Visibility.Collapsed;
                    LockControl.Visibility  = Visibility.Collapsed;
                }
            }
            catch { }
            try
            {
                await BackgroundExecutionManager.RequestAccessAsync();
            }
            catch { }
            try
            {
                UserNotificationListener listener = UserNotificationListener.Current;
                await listener.RequestAccessAsync();
            }
            catch { }
        }
コード例 #21
0
        async Task <int> getAccess()
        {
            //await Windows.ApplicationModel.FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();


            // Get the listener
            UserNotificationListener 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:

                if (!BackgroundTaskRegistration.AllTasks.Any(k => k.Value.Name.Equals("UserNotificationChanged")))
                {
                    // Specify the background task
                    var builder = new BackgroundTaskBuilder()
                    {
                        Name = "UserNotificationChanged"
                    };

                    // Set the trigger for Listener, listening to Toast Notifications
                    builder.SetTrigger(new UserNotificationChangedTrigger(NotificationKinds.Toast));

                    // Register the task
                    builder.Register();
                }

                IReadOnlyList <UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);

                IReadOnlyList <UserNotification> notifsUn = await listener.GetNotificationsAsync(NotificationKinds.Unknown);

                double notifCount = notifs.Count;
                if (notifCount > 0)
                {
                    UserNotification notif   = notifs[0];
                    string           message = notif.Notification.ToString();

                    if (notif.AppInfo.DisplayInfo.DisplayName != null)
                    {
                        // Get the app's display name
                        string appDisplayName = notif.AppInfo.DisplayInfo.DisplayName;
                    }

                    // Get the app's logo
                    BitmapImage appLogo = new BitmapImage();
                    RandomAccessStreamReference appLogoStream = notif.AppInfo.DisplayInfo.GetLogo(new Size(16, 16));
                    await appLogo.SetSourceAsync(await appLogoStream.OpenReadAsync());
                }

                // 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;
            }
            int i = 1;

            return(i);
        }