2017-03-10 13 views
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); 
     } 

からの放送を受信できない私は、コマンドを呼び出そうとしました。私はいくつかの設定が欠けていますか?これは、このアプリケーションの外部から呼び出される必要があります。BroadcastReceiverが正しい行動の意図

答えて

1

トースト用にShow();がありません。

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

これを追加した後、次のことができます。

adb shell am broadcast -a intent.action.ApiAiResponse 

または

adb shell am broadcast -a intent.action.ApiAiResponse --es intent.key.action "Hello.From.Xamarin" 
関連する問題