Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

c# - Toasted notifications action button is not working on lock screen

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...