0
   [BroadcastReceiver(Exported=true, Enabled=true)]
    [IntentFilter (new string[] 
        { 
            "intent.action.ApiAiResponse"
})]
    public class ApiAiVoiceReceiver : BroadcastReceiver
    {
        public const string ACTION = "intent.action.ApiAiResponse";
        public const string ACTION_KEY = "intent.key.action";
        public const string PARAMETERS_KEY = "intent.key.parameters";

        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action.Equals(ACTION))
            {
                Toast.MakeText(context, intent.GetStringExtra(ACTION_KEY), ToastLength.Long);
            } else
            Toast.MakeText(context, "", ToastLength.Long);
        }

I tried to call the command :

adb shell am broadcast -a intent.action.ApiAiResponse

But the ApiAiVoiceReceiver never called. Am I missing some setting? This have to be called by the outside of this application.

pinedax
  • 9,246
  • 2
  • 23
  • 30
LittleFunny
  • 8,155
  • 15
  • 87
  • 198

1 Answers1

1

You are missing the Show(); for the Toast.

Toast.MakeText(context, intent.GetStringExtra(ACTION_KEY), ToastLength.Long).Show();

After adding this you can:

adb shell am broadcast -a intent.action.ApiAiResponse

or

adb shell am broadcast -a intent.action.ApiAiResponse --es intent.key.action "Hello.From.Xamarin"
pinedax
  • 9,246
  • 2
  • 23
  • 30