← All projects

Android Call State Monitor

See who's calling, as it rings.

A small Android app that listens for changes in the phone's call state. When a call comes in, it shows the caller's number on screen while the phone is still ringing.

Listening

A receiver for every change in call state.

When the app starts, it registers a broadcast receiver for the system's phone state broadcast. Each time the state changes, the receiver attaches a listener to the phone's TelephonyManager, and when that listener sees the phone ringing, it shows the incoming number in a toast.

Permissions

It asks first.

Reading the phone's state and the incoming number needs the user's permission on modern Android. The app asks for phone state, call log and phone call access as soon as it opens, and declares what it uses in its manifest. Telephony hardware is marked optional, so the app still installs on devices without it.

And the details.

How it's built

Java, Android SDK, BroadcastReceiver.

The app is written in Java against the Android SDK and built with Gradle, using Kotlin build scripts. It comes down to two classes: MainActivity asks for permissions and registers the receiver, and MyCallsReceiver does the listening.

  1. BroadcastReceiver

    Registered at runtime with an IntentFilter for TelephonyManager.ACTION_PHONE_STATE_CHANGED when the activity starts.

  2. TelephonyManager

    On each broadcast the receiver gets the TelephonyManager system service and listens with a PhoneStateListener for LISTEN_CALL_STATE, acting on the ringing state.

  3. Permissions

    READ_PHONE_STATE and READ_CALL_LOG are declared in the manifest and requested at launch with CALL_PHONE. The incoming number is only shared with apps that hold call log access.

Android Call State Monitor. See who's calling, as it rings.

NextHearts Card GameHearts, in the terminal.