1

배경 작업의 토스트 알림을 표시 할 수있는 응용 프로그램을 작성했습니다. (BackgroundTaskBuilder를 사용합니다). 알림에서 두 개의 다른 기능을 수행해야하는 두 개의 버튼을 사용하고 있지만 알림의 응답을받을 수 없습니다.백그라운드 작업에서 토스트 알림 응답

나는 이것에 대한 다른 배경 작업을 시작해야한다는 것을 인터넷에서 읽었지만 backround 작업에서 다른 배경 작업을 시작할 수 없습니다.

제 궁금한 점은 : 알림을 클릭 한 사용자를 어떻게 알 수 있습니까?

도움 주셔서 감사합니다.

+0

유용한 것으로 보입니다. http://www.kunal-chowdhury.com/2016/02/uwp-tips-toast-button.html –

답변

5

Windows 10에서는 전경 또는 배경에서 토스트 알림 활성화를 처리 할 수 ​​있습니다. Windows 10에서는 <action> 요소에 activationType 특성을 갖는 적응 형 및 대화 형 알림을 소개합니다. 이 속성을 사용하면이 작업이 어떤 종류의 활성화를 유발할 지 지정할 수 있습니다. 예를 들어 다음과 토스트를 사용하면 : 사용자가 "자세한 내용을 참조하십시오"버튼을 클릭하면

<toast launch="app-defined-string"> 
    <visual> 
    <binding template="ToastGeneric"> 
     <text>Microsoft Company Store</text> 
     <text>New Halo game is back in stock!</text> 
    </binding> 
    </visual> 
    <actions> 
    <action activationType="foreground" content="See more details" arguments="details"/> 
    <action activationType="background" content="Remind me later" arguments="later"/> 
    </actions> 
</toast> 

enter image description here

, 그것은 전경에 응용 프로그램을 가져올 것이다. Application.OnActivated method은 새 activation kind - ToastNotification으로 호출됩니다. 그리고 우리는 다음과 같이이 활성화를 처리 할 수 ​​

protected override void OnActivated(IActivatedEventArgs e) 
{ 
    // Get the root frame 
    Frame rootFrame = Window.Current.Content as Frame; 

    // TODO: Initialize root frame just like in OnLaunched 

    // Handle toast activation 
    if (e is ToastNotificationActivatedEventArgs) 
    { 
     var toastActivationArgs = e as ToastNotificationActivatedEventArgs; 

     // Get the argument 
     string args = toastActivationArgs.Argument; 
     // TODO: Handle activation according to argument 
    } 
    // TODO: Handle other types of activation 

    // Ensure the current window is active 
    Window.Current.Activate(); 
} 

사용자가 클릭

버튼을 "나중에 알림", 그것은 전경 응용 프로그램을 활성화하는 대신 백그라운드 작업을 트리거합니다. 따라서 백그라운드 작업에서 다른 백그라운드 작업을 시작할 필요가 없습니다.

토스트 알림에서 백그라운드 활성화를 처리하려면 백그라운드 작업을 만들고 등록해야합니다. 백그라운드 작업은 앱 매니페스트에서 "시스템 이벤트" 작업으로 선언하고 트리거를 ToastNotificationActionTrigger으로 설정해야합니다. 그런 다음 백그라운드 작업에 같은 클릭되는 버튼을 결정하기 위해 미리 정의 된 인수를 검색 할 수 ToastNotificationActionTriggerDetail를 사용

public sealed class NotificationActionBackgroundTask : IBackgroundTask 
{ 
    public void Run(IBackgroundTaskInstance taskInstance) 
    { 
     var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; 

     if (details != null) 
     { 
      string arguments = details.Argument; 
      // Perform tasks 
     } 
    } 
} 

이 더 많은 정보 Adaptive and interactive toast notifications, 특히 Handling activation (foreground and background)를 참조하십시오. GitHub에 the complete sample도 있습니다.

+0

답장을 보내 주셔서 감사합니다. 나는 이것을 이해하지만 배경 작업에 알림을 만들고 표시하는 경우 어떻게 ToastNotificationActionTrigger에 대해 다른 알림을 시작할 수 있습니까? –

+0

@ SüliPatrik [공식 샘플] (https://github.com/WindowsNotifications/quickstart-sending-local-toast-win10)의 'ToastNotificationBackgroundTask'와 같은 새로운 백그라운드 작업을 추가하고 ToastNotificationBackgroundTask를 등록해야합니다. 그런 다음 원래 백그라운드 작업으로 토스트 알림을 보낼 수 있습니다. 예를 들어 공식 샘플의'ButtonSendToast_Click' 메소드에서와 같이 축배를 보내는 것으로 가정 해 봅시다. 그런 다음 건배에서 "좋아요"버튼을 클릭하면 'ToastNotificationActionTrigger'가 실행됩니다. ToastNotificationBackgroundTask가 시작됩니다. –

+2

@ SüliPatrik 원래 백그라운드 작업에서 'ToastNotificationBackgroundTask'를 시작하지는 않지만 토스트 알림을 클릭하면 ToastNotificationBackgroundTask가 시작되고이 백그라운드 작업에서 사용자가 클릭 한 버튼을'details.Argument '. –