How to pass data to BroadcastReceiver?

后端 未结 5 1000
难免孤独
难免孤独 2020-12-08 21:43

What I am trying to do is that the numbers to which my application sends messages to, are passed to the BraodcastReceiver...but so far either I am getting null or BroadcastR

5条回答
  •  情书的邮戳
    2020-12-08 22:02

    You would send a broadcast like so:

    Intent intent = new Intent(action);
    intent.putExtra("phN", phoneNo);
    sendBroadcast(intent);
    

    The action parameter is a String that correlates to the action you registered the BroadcastReceiver with. So if you registered your receiver like so:

    MyBroadcastReceiver receiver = new MyBroadcastReceiver();
    registerReceiver( receiver, new IntentFilter( "com.myapp.myaction" ) );
    

    then action would be "com.myapp.myaction"

提交回复
热议问题