Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Android uses the concept of a receiver and the concept of <code>"Broadcasting”</code> intents to help you essentially listen for certain actions that occur on the phone. You can implement a receiver to listen to your own intents which you might send around internally within your application (i.e. perhaps a change was made to one of your application’s data sets and you want to broadcast this to your receiver and have the receiver do some additional work), but again, receivers are most often used to listen to intents which are broadcasted by the system itself!</p> <p>For Example:</p> <p>In your Android manifest define a new receiver to be: </p> <blockquote> <pre><code>&lt;receiver android:name=".receivers.PhoneIntentReceiver" android:enabled="true"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.PHONE_STATE"&gt;&lt;/action&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> </blockquote> <p>Basically, you are defining a receiver object called <code>PhoneIntentReceiver</code> in your <code>manifest</code> which is enabled and which will listen for system broadcasts with the action type <code>PHONE_STATE</code>. This particular <code>intent</code> gets broadcasted by the system whenever there is an incoming call or whenever you hangup an existing phone call (i.e. when the state of your phone changes).</p> <p>And the actual class which will look something like this:</p> <blockquote> <pre><code> public class PhoneIntentReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //get the data from the passed intent //this is the intent that was broadcasted by the system Bundle bundle = intent.getExtras(); String phoneState = bundle.getString("state"); String phoneNumber = bundle.getString("incoming_number"); //perform operations using phoneState data } </code></pre> <p>}</p> </blockquote> <p>So notice we extend the <code>BroadcastReceiver</code> class and override the <code>onReceive</code> method. This gets called whenever the intent with action <code>PHONE_STATE</code> is broadcasted, and from there we can get the extra information that was stored in the <code>intent</code> and play around with it. Notice that in this case, the action extra is the “state”, and here the state will be either “RINGING”, “OFFHOOK”, or “IDLE”.</p> <p>I hope you will get the difference now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload