如何在Android小部件中实现语音识别?

时间:2014-04-30 05:12:05

标签: android android-intent widget android-widget voice-recognition

是否可以在小部件中引入语音识别?

我的问题是一个小部件从AppWidgetProvider扩展而且我不能使用onActivityResult方法,所以我不知道如何获取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, "Say something");

PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 0, voiceIntent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.voice_widget);
views.setOnClickPendingIntent(R.id.wid, pendingIntent2);

appWidgetManager.updateAppWidget( appWidgetId, views );

0 个答案:

没有答案