<i id='hPLdQ'><tr id='hPLdQ'><dt id='hPLdQ'><q id='hPLdQ'><span id='hPLdQ'><b id='hPLdQ'><form id='hPLdQ'><ins id='hPLdQ'></ins><ul id='hPLdQ'></ul><sub id='hPLdQ'></sub></form><legend id='hPLdQ'></legend><bdo id='hPLdQ'><pre id='hPLdQ'><center id='hPLdQ'></center></pre></bdo></b><th id='hPLdQ'></th></span></q></dt></tr></i><div id='hPLdQ'><tfoot id='hPLdQ'></tfoot><dl id='hPLdQ'><fieldset id='hPLdQ'></fieldset></dl></div>

    <tfoot id='hPLdQ'></tfoot>
      <bdo id='hPLdQ'></bdo><ul id='hPLdQ'></ul>
    1. <small id='hPLdQ'></small><noframes id='hPLdQ'>

        <legend id='hPLdQ'><style id='hPLdQ'><dir id='hPLdQ'><q id='hPLdQ'></q></dir></style></legend>

        调用语音识别应用程序的小部件

        时间:2023-09-09
          <tbody id='2Px1H'></tbody>
          <bdo id='2Px1H'></bdo><ul id='2Px1H'></ul>
        • <tfoot id='2Px1H'></tfoot>
          <i id='2Px1H'><tr id='2Px1H'><dt id='2Px1H'><q id='2Px1H'><span id='2Px1H'><b id='2Px1H'><form id='2Px1H'><ins id='2Px1H'></ins><ul id='2Px1H'></ul><sub id='2Px1H'></sub></form><legend id='2Px1H'></legend><bdo id='2Px1H'><pre id='2Px1H'><center id='2Px1H'></center></pre></bdo></b><th id='2Px1H'></th></span></q></dt></tr></i><div id='2Px1H'><tfoot id='2Px1H'></tfoot><dl id='2Px1H'><fieldset id='2Px1H'></fieldset></dl></div>

            <legend id='2Px1H'><style id='2Px1H'><dir id='2Px1H'><q id='2Px1H'></q></dir></style></legend>

            <small id='2Px1H'></small><noframes id='2Px1H'>

                  本文介绍了调用语音识别应用程序的小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个包含单个 ImageView 的小部件,单击该小部件会启动语音识别应用程序.我从来没有使用过小部件和待处理的意图,所以我很困惑:如何创建待处理的意图来启动语音识别活动?

                  我尝试过这样的事情,但它当然失败了:

                  <上一页>意图意图 = new Intent();意图 voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,识别器意图.LANGUAGE_MODEL_FREE_FORM);voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT,语音识别演示");voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT,voiceIntent);PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,意图,0);RemoteViews 视图 = 新 RemoteViews(context.getPackageName(),R.layout.main);views.setOnClickPendingIntent(R.id.button, pendingIntent);

                  解决方案

                  我明白了!我需要两个包裹在两个待处理意图中的常规意图,如下所示:

                  //这个意图指向应该处理结果的活动Intent activityIntent = new Intent(context, ResultsActivity.class);//这个意图包装了结果活动意图PendingIntent 结果PendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);//这个意图调用语音识别意图 voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "语音识别演示");voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent);//这个意图包装了语音识别意图PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, voiceIntent, 0);rv.setOnClickPendingIntent(R.id.btn, pendingIntent);

                  I'm trying to create a widget that contains a single ImageView which, when clicked, starts speech recognition application. I've never worked with widgets and pending intents, so I'm confused: how to create a pending intent for starting speech recognition activity?

                  I tried with something like this, but it, of course, fails:

                     Intent intent = new Intent();
                     Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                     voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                       RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                     voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT,
                       "Speech recognition demo");
                     voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                     intent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, voiceIntent);
                     PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                       intent, 0);
                     RemoteViews views = new RemoteViews(context.getPackageName(),
                       R.layout.main);
                     views.setOnClickPendingIntent(R.id.button, pendingIntent);
                  

                  解决方案

                  I got it! I needed two regular intents wrapped in two pending intents, like this:

                  // this intent points to activity that should handle results
                  Intent activityIntent = new Intent(context, ResultsActivity.class);
                  // this intent wraps results activity intent
                  PendingIntent resultsPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);
                  
                  // this intent calls the speech recognition
                  Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                  voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                  voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
                  voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent);
                  
                  // this intent wraps voice recognition intent
                  PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, voiceIntent, 0);
                  rv.setOnClickPendingIntent(R.id.btn, pendingIntent);
                  

                  这篇关于调用语音识别应用程序的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android O:我们可以做一个时钟小部件吗? 下一篇:以编程方式更改应用小部件背景颜色

                  相关文章

                    <legend id='KwUHk'><style id='KwUHk'><dir id='KwUHk'><q id='KwUHk'></q></dir></style></legend>
                      • <bdo id='KwUHk'></bdo><ul id='KwUHk'></ul>

                    1. <tfoot id='KwUHk'></tfoot>

                    2. <small id='KwUHk'></small><noframes id='KwUHk'>

                    3. <i id='KwUHk'><tr id='KwUHk'><dt id='KwUHk'><q id='KwUHk'><span id='KwUHk'><b id='KwUHk'><form id='KwUHk'><ins id='KwUHk'></ins><ul id='KwUHk'></ul><sub id='KwUHk'></sub></form><legend id='KwUHk'></legend><bdo id='KwUHk'><pre id='KwUHk'><center id='KwUHk'></center></pre></bdo></b><th id='KwUHk'></th></span></q></dt></tr></i><div id='KwUHk'><tfoot id='KwUHk'></tfoot><dl id='KwUHk'><fieldset id='KwUHk'></fieldset></dl></div>