title: intent.action.PHONE_STATE broadcast receiver not working when app closed
body: <p>i am trying to detect incoming calls by using this broadcast</p>
  <pre><code>   &lt;receiver android:name=&quot;.IncomingCallReceiver&quot;
                  android:enabled=&quot;true&quot;
      
                  android:exported=&quot;true&quot;&gt;
                  &lt;intent-filter android:priority=&quot;2147483647&quot;&gt;
                      &lt;action android:name=&quot;android.intent.action.PHONE_STATE&quot; /&gt;
                  &lt;/intent-filter  &gt;
                  &lt;intent-filter android:priority=&quot;2147483647&quot;&gt;
                      &lt;action android:name=&quot;android.intent.action.NEW_OUTGOING_CALL&quot; /&gt;
                  &lt;/intent-filter&gt;
              &lt;/receiver&gt;
  </code></pre>
  <p>and this is java code</p>
  <pre><code>public void onReceive(Context context, Intent intent) {
  
          if (intent.getAction().equals(&quot;android.intent.action.NEW_OUTGOING_CALL&quot;)) {
  //            savedNumber = intent.getExtras().getString(&quot;android.intent.extra.PHONE_NUMBER&quot;);
          }
          else{
              String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
              String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
              int state = 0;
              if(stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)){
                  state = TelephonyManager.CALL_STATE_IDLE;
              }
              else if(stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                  state = TelephonyManager.CALL_STATE_OFFHOOK;
              }
              else if(stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)){
                  state = TelephonyManager.CALL_STATE_RINGING;
              }
  
  
              onMyCallStateChanged(context, state, number);
          }
  
  
  //            TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  //            telephony.listen(new PhoneStateListener() {
  //                @Override
  //                public void onCallStateChanged(int state, String phoneNumber) {
  //
  //                    onMyCallStateChanged(context, state, phoneNumber);
  //                }
  //            }, PhoneStateListener.LISTEN_CALL_STATE);
          }
  </code></pre>
  <p>the issue is when app get closed or removed from recent this broadcast not working. in android <a href="https://developer.android.com/guide/components/broadcast-exceptions" rel="nofollow noreferrer">docs</a>, it is mentioned that this will work in the background</p>