C# Cortana语音命令无法正确启动应用程序

C# Cortana语音命令无法正确启动应用程序,c#,windows-phone-8.1,cortana,C#,Windows Phone 8.1,Cortana,我尝试使用Cortana语音命令启动我的应用程序 但它只有在应用程序挂起时才起作用。当应用程序关闭时,它会显示Splashscreen,然后应用程序失败。我无法捕捉到任何异常 A具有与in和麦克风功能完全相同的代码。当语音命令激活应用程序时,将调用此方法,而不会调用OnLaunched。因此,我们需要类似于OnLaunched中的代码 Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) {

我尝试使用Cortana语音命令启动我的应用程序

但它只有在应用程序挂起时才起作用。当应用程序关闭时,它会显示Splashscreen,然后应用程序失败。我无法捕捉到任何异常


A具有与in和麦克风功能完全相同的代码。

当语音命令激活应用程序时,将调用此方法,而不会调用OnLaunched。因此,我们需要类似于OnLaunched中的代码

Frame rootFrame = Window.Current.Content as Frame;

if (rootFrame == null)
{
     rootFrame = new Frame();
     rootFrame.CacheSize = 1;
     Window.Current.Content = rootFrame;
     rootFrame.Navigate(typeof(MainPage));
}

使用语音命令打开应用程序时,您需要在应用程序上进行处理。激活方法:

protected override void OnActivated(IActivatedEventArgs e)
{
//Cortana启动应用程序时的处理
if(e.Kind==ActivationKind.VoiceCommand)
{
VoiceCommandActivatedEventArgs commandArgs=e作为VoiceCommandActivatedEventArgs;
SpeechRecognitionResult SpeechRecognitionResult=commandArgs.Result;
字符串voiceCommandName=speechRecognitionResult.RulePath[0];
string textSpeaked=speechRecognitionResult.Text;
iReadOnly列表可识别DVoiceCommand短语;
System.Diagnostics.Debug.WriteLine(“voiceCommandName:+voiceCommandName”);
System.Diagnostics.Debug.WriteLine(“textSpeaked:+textSpeaked”);
开关(voiceCommandName)
...
如果您需要有关如何集成的更多信息,请参阅此

    protected override void OnActivated(IActivatedEventArgs e)
    {
        // Handle when app is launched by Cortana
        if (e.Kind == ActivationKind.VoiceCommand)
        {
            VoiceCommandActivatedEventArgs commandArgs = e as VoiceCommandActivatedEventArgs;
            SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;

            string voiceCommandName = speechRecognitionResult.RulePath[0];
            string textSpoken = speechRecognitionResult.Text;
            IReadOnlyList<string> recognizedVoiceCommandPhrases;

            System.Diagnostics.Debug.WriteLine("voiceCommandName: " + voiceCommandName);
            System.Diagnostics.Debug.WriteLine("textSpoken: " + textSpoken);

            switch (voiceCommandName)
            ...