Note that there are some explanatory texts on larger screens.

plurals
  1. POHiding default incoming call screen doesn't work all the time
    text
    copied!<p>I am working on application that receives incoming calls and automatically answers them. I have an activity that runs while a worker thread automatically answers the calls. What I would like to accomplish is to suppress the default incoming call screen and keep my activity in the foreground while it is running. </p> <p>After some research here, I have figured this can be accomplished by using a <strong>BroadcastReceiver</strong> and calling <strong>BroadcastReceiver.abortBroadcast()</strong> while setting <strong>android.intent.action.PHONE_STATE</strong> broadcast to the highest priority in my manifest. </p> <p>Unfortunately, this only works %50 of the time. Half the time I am able to answer the call and my activity remains in the foreground and half the time, that is not the case. How can I get this to work every time?</p> <p>Here is my manifest:</p> <pre><code> &lt;receiver android:enabled="true" android:name=".IncomingCallBroadcastReceiver"&gt; &lt;intent-filter android:priority="9999"&gt; &lt;action android:name="android.intent.action.PHONE_STATE"/&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>Here is my BroadcastReceiver: </p> <pre><code>public class IncomingCallBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(final Context arg0, Intent arg1) { Bundle extras = arg1.getExtras(); if (extras != null) { String state = extras.getString(TelephonyManager.EXTRA_STATE); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { // set a flag for worker thread to answer call } } try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } abortBroadcast(); } } </code></pre>
 

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