BroadcastReceiver error
<p>i wrote an app that when i press a button it start listen every call in the phone, and do something when there recieve a call...</p>

<p>however when i pressed the button and then when i recieve a call its wrote for me an error:
"unfortantly your app must stopped" and exit from the app</p>

<p>this is my app:</p>

<pre><code>public void onClick(View src) {
        switch(src.getId()) {

        case R.id.modebutton:
            //start service
            if(modebutton.getText().equals("Active")) {
                incomingcall=new IncomingCallInterceptor ();
                modebutton.setText("Disable");
            }
            //disable 
            else {
                PackageManager pm = getPackageManager();
                ComponentName componentName = new ComponentName(this, IncomingCallInterceptor.class);
                pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
                modebutton.setText("Active");
            }



public class IncomingCallInterceptor extends BroadcastReceiver {


        @Override 
        public void onReceive(final Context context, Intent intent) {                                         
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);                         


            if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {                                   
                String name = null;
                String contactId = null;
                // Phone is ringing
                Bundle extras = intent.getExtras();
                if (extras != null) {
                }
                String[] projection = new String[] {
                        ContactsContract.PhoneLookup.DISPLAY_NAME,
                        ContactsContract.PhoneLookup._ID};

                String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
             // encode the phone number and build the filter URI
                Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));

                // query time
                Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null);

                if (cursor.moveToFirst()) {

                    // Get values from contacts database:
                    contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID));
                    name =      cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));


                }


            }
        }
    }
</code></pre>

<p>also this is the permisiions in the manigest file:</p>

<pre><code>&lt;receiver android:name="IncomingCallInterceptor"&gt;                    
                &lt;intent-filter&gt;
                     &lt;action android:name="android.intent.action.PHONE_STATE"/&gt;   
                &lt;/intent-filter&gt;
        &lt;/receiver&gt;
    &lt;/application&gt;
    &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
    &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt;
    &lt;uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
    &lt;uses-permission android:name="android.permission.CALL_PHONE"&gt;&lt;/uses-permission&gt;
    &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;     
</code></pre>

<p>i hope someone will help me..thanks in advance</p>

<p>another code that i tried:</p>

<hr>

<pre><code>public void onClick(View src) {
        switch(src.getId()) {

        case R.id.modebutton:
            //start service
            if(modebutton.getText().equals("Active")) {

                TelephonyManager tm = (TelephonyManager) getSystemService(Service.TELEPHONY_SERVICE);   
                PhoneStateListener listener=new PhoneStateListener(){
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                // TODO Auto-generated method stub

                super.onCallStateChanged(state, incomingNumber);
                switch(state){
                case TelephonyManager.CALL_STATE_IDLE:
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    if(incomingNumber==null)
                                   {
                                     //outgoing call
                                    }
                                 else
                                    {
                                     //incoming call
                                    }
                    break;
                case TelephonyManager.CALL_STATE_RINGING:

                          if(incomingNumber==null)
                            {
                              //outgoing call
                            }
                           else
                            {
                              //incoming call
                            }
                    break;
                }
            }

        };
        tm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);



                modebutton.setText("Disable");
                break;
            }
</code></pre>

<p>however when i press the Active button and then i recieve a call to my phone, the phone exit from my app and write:unfortaanetly your app must be closed"</p>

<p>what can i do?</p>
