Android default dialer replacement (part I)

Miguel Barrios
Making Tuenti
Published in
3 min readMar 22, 2018

In Android 6.0 (Marshmallow), back in 2015, Google introduced a new feature called “Default phone app” so users could decide which dialer to use if they wanted other that the one shipped with their devices. They accordingly added a new set of classes to the API inside the package android.telecom so developers could implement their own dialer replacement app such as TelecomManager, InCallService, Call, etc. But the only documentation on how to proceed using this API is the one you can find in the API reference right on those previous links. There’s no official blog post about it so far and I couldn’t find any documentation from the development community either, other than a few questions on StackOverflow.

Permissions

Funny enough, you don’t need to ask for any permissions. No READ_PHONE_STATE or CALL_PHONE. Runtime permissions were also introduced in Android 6.0, but in this case you won’t need any of them. You’ll need to ask the user to give you the privilege of being the default phone app instead, but we will go there later.

Intent filters

Well, you might think that at least you’ll need to be able to receive some intents. And yes, you are implementing a dialer app, so you’ll need to add to your manifest an Activity with intent filters to be able to receive the DIAL Intent.

You’ll need to add those two intent filters to your Activity. Removing or modifying one of them results in your app not being eligible as default dialer. You can add other intent filters though, for instance one for declaring your Activity as the launcher one.

A Service

In order to receive callbacks from the OS with the info needed to handle phone calls, you need to implement an InCallService and register it as well in the manifest.

And the implementation of the Service itself.

InCallService is an abstract class, so we don’t need to implement every method, only those we really want to use. In order to qualify as a dialer replacement you don’t need to implement any, we’ll do it once we want to start rendering our UI.

And that’s it, compile an apk with this two things and then you’ll be able to choose the app as a phone app in your device settings.

Ask the user

One more thing we need to do is asking the user whether she wants our app to replace the stock dialer whenever she opens the app, similarly to what we do with runtime permissions. So, in our main activity, we’re going to:

  • Check if the app is already the default dialer with TelecomManager.getDefaultDialerPackage
  • If it’s not, we start an Activity with the action TelecomManager.ACTION_CHANGE_DEFAULT_DIALER and our app’s package as an Intent extra.
  • Listen for the result of the started Activity and show an informative Toast.

Most of TelecomManager methods are only available from Android 6.0 onwards, so don’t forget to check the SDK version.

And that’s it for now, thanks for reading. In a second post we’ll cover how to listen to InCallService callbacks and render a proper call UI, and even answering or rejecting calls. You can also have a look at the Github repo with the full solution already implemented.

--

--