diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml
index f21d2e1ac..233b37f79 100644
--- a/astrid/AndroidManifest.xml
+++ b/astrid/AndroidManifest.xml
@@ -32,6 +32,8 @@
+
+
@@ -198,6 +200,12 @@
+
+
+
+
+
+
diff --git a/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java
new file mode 100644
index 000000000..ceacadfa3
--- /dev/null
+++ b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java
@@ -0,0 +1,56 @@
+package com.todoroo.astrid.calls;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.database.Cursor;
+import android.provider.CallLog.Calls;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+
+import com.todoroo.andlib.utility.Preferences;
+
+@SuppressWarnings("nls")
+public class PhoneStateChangedReceiver extends BroadcastReceiver {
+
+ private static final String PREF_LAST_INCOMING_NUMBER = "last_incoming_number";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
+
+ if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
+ String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
+ System.err.println("Ringing: " + number);
+ if (TextUtils.isEmpty(number))
+ return;
+
+ Preferences.setString(PREF_LAST_INCOMING_NUMBER, number);
+ } else if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
+ String lastNumber = Preferences.getStringValue(PREF_LAST_INCOMING_NUMBER);
+ if (TextUtils.isEmpty(lastNumber))
+ return;
+
+ Preferences.clear(PREF_LAST_INCOMING_NUMBER);
+ Cursor calls = context.getContentResolver().query(
+ Calls.CONTENT_URI,
+ null,
+ Calls.TYPE + " = ? AND " + Calls.NEW + " = ? AND " + Calls.NUMBER + " = ?" ,
+ new String[] { Integer.toString(Calls.MISSED_TYPE), "1", lastNumber },
+ Calls.DATE + " DESC"
+ );
+
+ try {
+ if (calls.getCount() > 0) {
+ calls.moveToFirst();
+ System.err.println("Should display notification for number: " + lastNumber);
+ }
+ } finally {
+ calls.close();
+ }
+ } else {
+ System.err.println("Other state: " + state);
+ }
+ }
+
+}