Cortana 集成失败

Cortana integration faliure

我正在制作一个 Windows 基于 8.1 语音的应用程序。我的问题是,当我给 Cortana 输入时,它会启动我的应用程序,然后应用程序会在闪屏处关闭,但是当我 运行 我的应用程序在后台(最小化应用程序)或当应用程序处于 运行ning 时, Cortana 输入完美无缺。

我哪里错了?这是我的 app.xaml.cs 代码,在 OnActivatedMethod:

if (args.Kind == ActivationKind.VoiceCommand)
        {
            VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

            string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?

            switch (voiceCommandName) // Run the action specific to the command
            {
                case "comand1": // User said comand1
                    rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
                    break;

                case "comand2": // User said comand2
                    rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
                    break;
                case "comand3": // User said comand3
                    rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
                    break;
                case "comand4":
                    rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
                    break;
            }

并且在语音处理页面的OnNavigated方法中:

SpeechRecognitionResult vcArgs = e.Parameter as SpeechRecognitionResult;
        RcvdCommand = vcArgs.Text.ToUpper();

        // Check for null!
        string commandMode = vcArgs.SemanticInterpretation.Properties["commandMode"][0];

        if (commandMode == "voice") // Did the user speak or type the command?
        {
            RequestHanding();
            MyTextblock.Text = vcArgs.Text;
            // SpeakText(audioPlayer, String.Format(" app heard you say {0}", RcvdCommand ));

            // HandleNlpCommand(vcArgs);
        }
        else if (commandMode == "text")
        {
            // messageTextBox.Text = string.Format("Working on your request \"{0}\"", RcvdCommand);

            // HandleNlpCommand(vcArgs);
        }

当应用程序不是运行并且是通过语音命令激活时,不会调用OnLaunched() 方法。因此,您还需要调用确保在 OnActivated() 方法中创建根框架的代码:

  Frame rootFrame = Window.Current.Content as Frame;

  // Do not repeat app initialization when the Window already has content,
  // just ensure that the window is active
  if (rootFrame == null)
  {
    // Create a Frame to act as the navigation context and navigate to the first page
    rootFrame = new Frame();

    // ... restore app state, etc.

    Window.Current.Content = rootFrame;
  }