C# 语音识别器&x27;不要调用ActivityResult
当我在android中使用语音识别器时。intent从不调用OnActivityResult方法。调试器从不在方法的第一行捕获它。此代码根据示例进行修改,以合并Xamarin表单C# 语音识别器&x27;不要调用ActivityResult,c#,android,android-intent,xamarin.android,speech-recognition,C#,Android,Android Intent,Xamarin.android,Speech Recognition,当我在android中使用语音识别器时。intent从不调用OnActivityResult方法。调试器从不在方法的第一行捕获它。此代码根据示例进行修改,以合并Xamarin表单 private const int Voice = 10; public void RecordSpeech() { Intent voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech); voiceIntent.PutExtr
private const int Voice = 10;
public void RecordSpeech()
{
Intent voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500);
voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500);
voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000);
voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1);
voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default);
((Activity)Forms.Context).StartActivityForResult(voiceIntent, Voice);
//This doesn't work either
//((Activity)Forms.Context).StartActivityForResult(Intent.CreateChooser(new Intent(voiceIntent), "voiceIntent"), Voice);
}
protected override void OnActivityResult(int requestCode, Result resultVal, Intent data)
{ //A break point here doesn't work
Debug.WriteLine("Debug");
if (requestCode == Voice)
{
if (resultVal == Result.Ok)
{
IList<string> matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
if (matches.Count != 0)
{
Debug.WriteLine(matches[0]);
}
}
}
base.OnActivityResult(requestCode, resultVal, data);
}
private const int Voice=10;
公众演讲
{
Intent voiceIntent=新意图(RecognizerIntent.ActionRecognizeSpeech);
voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel,RecognizerIntent.LanguageModelFreeForm);
voiceIntent.PutExtra(识别器Intent.ExtraspeechInputCompleteSilenceLength,1500);
voiceIntent.PutExtra(识别器Intent.ExtraspeechInputPossiblyCompleteSilenceLength,1500);
voiceIntent.PutExtra(识别器Intent.ExtraSpeechInputMinimumLengthMillis,15000);
voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults,1);
PutExtra(RecognizerIntent.ExtraLanguage,Java.Util.Locale.Default);
((活动)Forms.Context)StartActivityForResult(语音意图,语音);
//这也不行
//((活动)Forms.Context).StartActivityForResult(Intent.CreateChooser(新意图(voiceIntent),“voiceIntent”),Voice;
}
受保护的覆盖void OnActivityResult(int请求代码、结果瓦尔、意图数据)
{//这里的断点不起作用
Debug.WriteLine(“调试”);
if(requestCode==语音)
{
if(resultVal==Result.Ok)
{
IList matches=data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
如果(matches.Count!=0)
{
Debug.WriteLine(匹配[0]);
}
}
}
base.OnActivityResult(请求代码、结果瓦尔、数据);
}
OnActivityResult需要在MainActivity类中。把它放在那里修复了一切