title: Pop up window over Android native incoming call screen like true caller Android app
body: <p>I am developing a broadcast receiver for incoming calls in Android and on getting incoming calls I want to inflate a pop up over the native incoming call screen.</p>
  <p>I completed that code. But now the problem is that in the <a href="http://en.wikipedia.org/wiki/Android_version_history#Android_4.2_Jelly_Bean_.28API_level_17.29" rel="noreferrer">Android 4.1 (Jelly Bean) API level 17</a> when a phone rings, the <code>PHONE_STATE</code> is coming as <code>OFF HOOK</code>, and if I am calling an activity, it gets called, but the code under it doesn't get executed. I am listing the code:</p>
  <h3>My broadcast receiver</h3>
  <pre><code>package com.example.popwindowonincomingcallscreen;
  
  import java.util.concurrent.Executors;
  import java.util.concurrent.ScheduledExecutorService;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  
  public class IncomingBroadcastReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          Log.d(&quot;IncomingBroadcastReceiver: onReceive: &quot;, &quot;flag1&quot;);
  
          String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
          Log.d(&quot;IncomingBroadcastReceiver: onReceive: &quot;, state);
          if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)
                  || state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
  
              Log.d(&quot;Ringing&quot;, &quot;Phone is ringing&quot;);
  
              Intent i = new Intent(context, IncomingCallActivity.class);
              i.putExtras(intent);
              i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
              Wait.oneSec();
              context.startActivity(i);
          }
      }
  }
  </code></pre>
  <p>An the activity which I am calling:</p>
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  import android.view.View.MeasureSpec;
  import android.view.Window;
  import android.view.WindowManager;
  import android.widget.TextView;
  
  public class IncomingCallActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          try {
              Log.d(&quot;IncomingCallActivity: onCreate: &quot;, &quot;flag2&quot;);
  
              */ After this line, the code is not executed in Android 4.1 (Jelly Bean) only/*
  
              // TODO Auto-generated method stub
              super.onCreate(savedInstanceState);
  
              getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
              getWindow().addFlags(
                      WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
  
              Log.d(&quot;IncomingCallActivity: onCreate: &quot;, &quot;flagy&quot;);
  
              setContentView(R.layout.main);
  
              Log.d(&quot;IncomingCallActivity: onCreate: &quot;, &quot;flagz&quot;);
  
              String number = getIntent().getStringExtra(
                      TelephonyManager.EXTRA_INCOMING_NUMBER);
              TextView text = (TextView) findViewById(R.id.text);
              text.setText(&quot;Incoming call from &quot; + number);
          } 
          catch (Exception e) {
              Log.d(&quot;Exception&quot;, e.toString());
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>After</p>
  <pre><code>try {
      Log.d(&quot;IncomingCallActivity: onCreate: &quot;, &quot;flag2&quot;);
  }
  </code></pre>
  <p>The code is not executing in Android 4.1 (Jelly Bean), but in other versions it is working.</p>
  <p>I have tried almost all ways I can do. This code is displaying an translucent activity over the native call screen, and it doesn't block background controls, like picking up the phone. But I want it like true caller. I have attached an snapshot on how the true caller is displaying a window on the incoming call screen.</p>
  <p>How can I achieve this functionality for an Android app?</p>
  <p>This is how a true caller works:</p>
  <p><img src="https://i.stack.imgur.com/lcVZy.png" alt="Enter image description here" /></p>
  <p>My present output:</p>
  <p><img src="https://i.stack.imgur.com/jh8Pe.jpg" alt="Enter image description here" /></p>
  <h2>Update 1</h2>
  <p>After bounty also I am not getting the exact thing I am looking for, but I will get back to all; I am working upon it. Anyway, this code works for most Android phones. If anybody is going to use and catch the solution for it, please write here so that everybody can get the benefit.</p>
  <h2>Update 2</h2>
  <p>I tried to implement Toast in the broadcast receiver's onReceive method because toast is a native component of Android, but it is also not getting displayed in Android 4.1 (Jelly Bean).</p>
  <p>My idea was to implement Toast in the broadcast receiver's onReceive method and afterwards changing its design according to our needs and tuning its duration of display. But one more problem is that <strong>findViewById</strong> doesn't work in the broadcast receiver, so I think we have to make a LinearLayout programmatically for customizing the toast.</p>