Toasted notifications action button is not working on lock screen

試著忘記壹切 提交于 2019-12-25 18:48:36

问题


I am building music player in uwp. Action buttons on the toasted notification are working fine when windows are unlocked. when i locked the screen and click on action button then nothing is happening. Application is going to pause state, no break points are getting hit.

How can i make my application to run even when windows is locked to receive events from app?

Another problem I am facing is when user clicks on next, previous buttons notification screen goes away.

How can i keep the Toasted notification screen on the machine even after user clicks on any action button.

Code i am using to create notification

var toastContent = new ToastContent
            {
                Launch= "",
                Visual = new ToastVisual
                {
                    BindingGeneric = new ToastBindingGeneric
                    {
                        Children =
                        {
                            new AdaptiveText
                            {
                                 HintWrap = false,
                            HintMaxLines = 1,
                            HintStyle = AdaptiveTextStyle.Title,
                                Text = "sdfsd"
                            },
                            new AdaptiveText
                            {
                                 HintWrap = false,
                            HintMaxLines = 1,
                            HintStyle = AdaptiveTextStyle.Caption,
                                Text = "text"
                            }
                        },

                        AppLogoOverride = new ToastGenericAppLogo()
                        {
                            Source = optionalLogoPath
                        }
                    }
                },
                Actions = new ToastActionsCustom()
                {
                    Buttons =
                {
                    new ToastButton("previous", new QueryString()
                    {
                        { "action", "previous" }

                    }.ToString() )
                    {
                        ActivationType= ToastActivationType.Foreground,
                        ImageUri = "prev-focus.png",

                    },
                    new ToastButton("Play", new QueryString()
                    {
                        { "action", "play" }

                    }.ToString() )
                    {
                        ActivationType= ToastActivationType.Foreground,
                        ImageUri = "play-focus.png",

                    },
                    new ToastButton("next", new QueryString()
                    {
                        { "action", "next" }

                    }.ToString() )
                    {
                        ActivationType= ToastActivationType.Background,
                        ImageUri = "next-focus.png"
                    },

                },
                }
            };

            var toast = new ToastNotification(toastContent.GetXml())
            {
                Tag = "some tag",
                SuppressPopup = false
            };

            toastNotifier.Show(toast);

Thanks in advance


回答1:


Finally i got it working by using protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args) method.



来源:https://stackoverflow.com/questions/55057690/toasted-notifications-action-button-is-not-working-on-lock-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!