前言
如果你希望開發一支UWP在背景處理事情, 然後將處理完的資料或狀態顯示在Cortana的Canvas上面的話, 我們會需要寫一個backgound server去處理Cortana的請求, 而基本上有以下幾個步驟Step 1. 前置步驟
新增專案
選擇Windows Runtime Component專案建立好之後, 我們先把Class1.cs重新命名(列如 MyVoiceCommandService.cs)
設定Package.appxmanifest
加入以下的程式碼, 然後把EntryPoint指定到剛剛建立的MyVoiceCommandService.cs編輯VoiceCommand.xml
實作IBackgroundTask
Step 2. 處理Cortana VoiceCommand的請求
取得VoiceCommandServiceConnection實體
這是用來讓我們的背景程式與Cortana溝通的介面建立Response的內容
基本上我們可以回傳VoiceCommandUserMessage, VoiceCommandContentTile這兩種內容給CortanaUser Messag
讓Cortana說話, 或是讓她秀訊息在Canvas上面
Content Tile
這個有點像是Bot Framework中的Card, 我們可以把文字跟圖片塞在Content Tile中讓Canvas顯示出來, 我們可以一次回傳多個Content Tile, 當使用者點了其中一個之後, 就會觸發開啟我們程式的事件
VoiceCommandResponse
建立VoiceCommandResponse的實體, 然後塞入剛剛建立的VoiceCommandUserMessage 或是 VoiceCommandContentTile, 最後再透過VoiceCommandServiceConnection回傳給CortanaDemo
Hey Cortana, find God Father on My Library
留言
張貼留言