首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cortana语音命令不能正确启动app

Cortana语音命令不能正确启动app
EN

Stack Overflow用户
提问于 2015-02-13 12:09:12
回答 2查看 572关注 0票数 0

我试过Cortana语音命令来启动我的应用程序,

但是,只有当应用程序被暂停时,它才能工作。当app关闭时,它会显示Splash屏,然后app失败。我不能抓住任何例外。

A具有与https://msdn.microsoft.com/en-us/library/dn630430.aspx和麦克风功能完全相同的代码。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-16 20:27:12

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

代码语言:javascript
复制
Frame rootFrame = Window.Current.Content as Frame;

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

Stack Overflow用户

发布于 2015-07-13 14:22:16

当使用语音命令打开应用程序时,需要在app.OnActivated方法上处理它:

代码语言:javascript
复制
    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)
            ...

如果您需要更多关于如何集成它的信息,请参阅此链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28499314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档