Reputation: 8405
[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.
Upvotes: 0
Views: 525
Reputation: 9356
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"
Upvotes: 1