我在xamarin app中的语音交互有问题。 在android项目中我在intentFilter中添加了Intent.CategoryVoice,然后在onResume上我有一个始终为false的if(!isvoiceInteraction)。 应用程序不回答我,因为isvoiceInteraction是false。为什么??我需要许可吗?还有什么?
[Activity(Label = "app", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionCall }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryVoice })]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
protected override void OnResume()
{
base.OnResume();
if (!IsVoiceInteraction)
return;
var front = new VoiceInteractor.PickOptionRequest.Option("Aiuto", 0);
var prompt = new VoiceInteractor.Prompt("Which camera would you like to use?");
var request = new CameraChoiceRequest(prompt, new[] { front });
VoiceInteractor.SubmitRequest(request);
}
protected class CameraChoiceRequest : VoiceInteractor.PickOptionRequest
{
public CameraChoiceRequest(VoiceInteractor.Prompt prompt, Option[] choices)
: base(prompt, choices, null)
{
}
public override void OnPickOptionResult(bool finished, Option[] selections, Bundle result)
{
base.OnPickOptionResult(finished, selections, result);
if (!finished || selections.Length != 1)
return;
Activity.Intent.PutExtra("android.intent.extra.USE_FRONT_CAMERA", selections[0].Index == 0);
}
}
}