Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cortana VCD: set command's Navigate target to a Page in a subfolder

I'm having trouble launching a specific page of my Windows Phone 8.1 app via Cortana. I've registered a VCD and the command is successfully being recognized by Cortana. But when the command is executed the app will launch its default page (MainPage.xaml). I want to launch the ReportPage.xaml instead of MainPage.xaml.

All pages are under a subfolder called "View" (unlike the default project template when creating an app).

I've tried several combinations but none worked:

<Navigate Target="ReportPage.xaml" />
<Navigate Target="View/ReportPage.xaml" />
<Navigate Target="/View/ReportPage.xaml" />
<Navigate Target="ReportPage" />

Here's my VCD:

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
  <CommandSet xml:lang="en-US">
    <CommandPrefix>Traffic Reporter</CommandPrefix>
    <Example>Report a traffic incident</Example>

    <Command Name="ReportIncident">
      <Example>Start reporting a traffic incident</Example>
      <ListenFor>Report</ListenFor>
      <ListenFor>Report an {SortOfIncident}</ListenFor>
      <ListenFor>Report a {SortOfIncident}</ListenFor>
      <Feedback>Starting the report</Feedback>
      <Navigate Target="ReportPage.xaml" />
    </Command>

    <PhraseList Label="SortOfIncident">
      <Item>accident</Item>
      <Item>incident</Item>
      <Item>speed trap</Item>
      <Item>speed check</Item>
    </PhraseList>

  </CommandSet>
</VoiceCommands>
like image 712
SolveSoul Avatar asked Dec 07 '25 02:12

SolveSoul


1 Answers

Assuming you are in a Windows Store App (WinRT): Do you handle the voice activation in you App.OnActivated Method?

protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.VoiceCommand)
    {
        Frame rootFrame = Window.Current.Content as Frame;
        VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

        //check for the command name that launched the app
        string voiceCommandName = vcArgs.Result.RulePath.FirstOrDefault();

        switch (voiceCommandName)
        {
            case "ViewEntry":
                rootFrame.Navigate(typeof(ViewDiaryEntry), vcArgs.Result.Text);
                break;
            case "AddEntry":
            case "EagerEntry":
                rootFrame.Navigate(typeof(AddDiaryEntry), vcArgs.Result.Text);
                break;
        }
    }
}
like image 69
Kai Brummund Avatar answered Dec 08 '25 16:12

Kai Brummund



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!