Activity popups over incoming call screen
<p>I'm trying to override the incoming call screen - I know I can't change it so I'm trying to popup an activity ontop.</p>

<p>My code works fine except when the phone has been idle for a few minutes.</p>

<p>My code:</p>

<p><strong>AndroidManifest.xml :</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.myfirstapp"
      android:versionCode="7"
      android:versionName="7"&gt;
    &lt;uses-sdk android:minSdkVersion="7" android:targetSdkVersion="10"&gt;&lt;/uses-sdk&gt;
    &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
    &lt;uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/&gt;
    &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;

    &lt;application android:label="@string/app_name" android:icon="@drawable/ic_launcher"&gt;
        &lt;receiver android:name=".MyPhoneBroadcastReceiver" android:enabled="true"&gt;
            &lt;intent-filter android:priority="99999"&gt;
                &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;
        &lt;activity
            android:name=".Call" &gt;
        &lt;/activity&gt;
    &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p><strong>MyPhoneBroadcastReceiver.java:</strong></p>

<pre><code>public class MyPhoneBroadcastReceiver extends BroadcastReceiver{

    public void onReceive(final Context context, Intent intent) {

        Thread pageTimer = new Thread(){
            public void run(){
                try{
                    sleep(700);
                } catch (InterruptedException e){
                    e.printStackTrace();
                } finally {
                    Intent i = new Intent();
                    i.setClass(context, Call.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);  
                    i.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
                    i.putExtra("INCOMING_NUMBER", incomingNumber);
                    i.setAction(Intent.ACTION_MAIN);
                    i.addCategory(Intent.CATEGORY_LAUNCHER);
                    context.startActivity(i);
                }
            }
        };
        pageTimer.start();
    }
}
</code></pre>

<p><strong>Call.java:</strong></p>

<pre><code>package com.example.myfirstapp;

import android.app.Activity;
import android.os.Bundle;

public class Call extends Activity{

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    getWindow().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    setContentView(R.layout.main);
    }

}
</code></pre>

<p>BTW - I tried waiting for the screen to wake up before the sleep(700) and it didn't help
(in MyPhoneBroadcastReceiver.java)</p>

<pre><code>...
try {      
    if (pm.isScreenOn()) {
        sleep(700);
    } else {
        while (!pm.isScreenOn()) {
            // Do nothing...
        }
        sleep(700);
    }
}        
</code></pre>

<p>...</p>
