title: How to detect incoming calls, in an Android device?
body: <p>I'm trying to make an app like, when a call comes to the phone I want to detect the number. Below is what I tried, but it's not detecting incoming calls. </p>
  
  <p>I want to run my <code>MainActivity</code> in background, how can I do that?</p>
  
  <p>I had given the permission in <code>manifest</code> file.</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
  </code></pre>
  
  <p>Is there anything else should I provide in the manifest?</p>
  
  <pre><code>public class MainActivity extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.test_layout);
     }
  
     public class myPhoneStateChangeListener extends PhoneStateListener {
         @Override
         public void onCallStateChanged(int state, String incomingNumber) {
             super.onCallStateChanged(state, incomingNumber);
             if (state == TelephonyManager.CALL_STATE_RINGING) {
                 String phoneNumber =   incomingNumber;
             }
         }
     }
  }
  </code></pre>