Невозможно отобразить данные на холсте Cortana
Я занимаюсь разработкой приложения UWP, в котором я хочу отобразить некоторые данные на холсте. Но я сталкиваюсь с множеством проблем, и теперь я не могу понять, в чем проблема. Я создал VCD-файл, добавил в него команду, отредактировал функцию OnActivation, выполнил задачу компонента времени выполнения Windows для фонового приложения, а также сделал объявление в файле Package.appxmanifest, но он не работает. Вот файл VoiceCommandDefinition.xml:
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="NormalCommands">
<CommandPrefix>in app</CommandPrefix>
<Example>Show data in canvas</Example>
<Command Name="CanvasView">
<Example>test cortana</Example>
<ListenFor RequireAppName="ExplicitlySpecified"> {builtin:Cortinnum}test cortana</ListenFor>
<Feedback>Okay Boss</Feedback>
<VoiceCommandService Target="CanvasViewService"/>
</Command>
</CommandSet>
</VoiceCommands>
Вот функция OnActivation из кода App.xaml.cs:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == Windows.ApplicationModel.Activation.ActivationKind.VoiceCommand)
{
var CommandArgs = args as Windows.ApplicationModel.Activation.VoiceCommandActivatedEventArgs;
var result = CommandArgs.Result;
var CommandName = result.RulePath[0];
var text = result.Text;
}
else
base.OnActivated(args);
}
Вот код компонента Фоновая служба:
using System;
using Windows.ApplicationModel.AppService;
using Windows.ApplicationModel.Background;
using Windows.ApplicationModel.VoiceCommands;
namespace BackgroundService
{
public sealed class service:IBackgroundTask
{
VoiceCommandServiceConnection voiceServiceConnection;
BackgroundTaskDeferral serviceDeferral;
public async void Run(IBackgroundTaskInstance taskInstance)
{
serviceDeferral = taskInstance.GetDeferral();
taskInstance.Canceled += OnTaskCanceled;
var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;
if (triggerDetails != null && triggerDetails.Name == "CanvasView")
{
try
{
voiceServiceConnection =
VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
triggerDetails);
voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;
VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();
// perform the appropriate command.
switch (voiceCommand.CommandName)
{
case "CanvasView":
VoiceCommandUserMessage userMessage = new VoiceCommandUserMessage();
userMessage.DisplayMessage = "Test Data";
userMessage.SpokenMessage = "Test data view successful";
var response = VoiceCommandResponse.CreateResponse(userMessage);
await voiceServiceConnection.ReportSuccessAsync(response);
break;
default:
VoiceCommandUserMessage userMessage1 = new VoiceCommandUserMessage();
userMessage1.DisplayMessage = "Nothing";
userMessage1.SpokenMessage = "NO data to show";
var response1 = VoiceCommandResponse.CreateResponse(userMessage1);
await voiceServiceConnection.ReportSuccessAsync(response1);
break;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
}
}
}
private void OnVoiceCommandCompleted(VoiceCommandServiceConnection sender, VoiceCommandCompletedEventArgs args)
{
if (this.serviceDeferral != null)
{
this.serviceDeferral.Complete();
}
}
private void OnTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
System.Diagnostics.Debug.WriteLine("Task cancelled, clean up");
if (this.serviceDeferral != null)
{
//Complete the service deferral
this.serviceDeferral.Complete();
}
}
}
}
Изменить: Вот код тега расширений из Package.appxmanifest:
<Extensions>
<uap:Extension Category="windows.appService" EntryPoint="Cortinnum.backgroundService.service">
<uap:AppService Name="service" />
</uap:Extension>
</Extensions>