register and unregister broadcast
<p>I am to create an application.Through my application users can read the incoming phone number.My activity have two buttons, On and off. If the user clicks the on button ,then the following code will execute.</p>

<pre><code>IntentFilter filter=new IntentFilter(TelephonyManager.EXTRA_STATE);
registerReceiver(new MyPhoneReceiver(), filter);
</code></pre>

<p>And If the user clicks the off button ,then the following code will execute.</p>

<pre><code>unregisterReceiver(new MyPhoneReceiver());
</code></pre>

<p>MyPhoneReceiver is my brcastreceiver calss name.If the user is click the on button then the onReceive() method will be ready to read incoming call number and display that number.Likewise if I click the off button, then broadcast will be unregistered.
My onRecieve() code is</p>

<pre><code>public void onReceive(Context context, Intent intent) {
System.out.println("am hereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
    Bundle extras = intent.getExtras();
    if (extras != null) {
        String state = extras.getString(TelephonyManager.EXTRA_STATE);
        Log.w("sarath DEBUG", state);
        System.out.println("state is:"+state);
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Log.w("sarath DEBUG", phoneNumber);
            System.out.println("phone no. is:"+phoneNumber);


        }
    }
}
</code></pre>

<p>My problem is when i click the on button nothing is happening.when a incoming call came then also its not executing onRecive() code.please help me friends</p>
