Replacing the native dialer application involves two steps:
1. Intercepting Intents that are currently serviced by the native dialer.
2. Initiating, and optionally managing, outgoing calls.
The native dialer application currently responds to Intent actions corresponding to a user's pressing the hardware call button, asking to view data using the tel: schema, or making a request to dial a number using the tel: schema.
To intercept these requests include <intent-filter> tags on your new Activity that listens for the following actions:
> Intent.ACTION_CALL_BUTTON This action is broadcast when the device's hardware call button is pressed. Create an Intent Filter listening for this action as a default action.
> Intent.ACTION_DIAL The Intent action described in the previous section, this Intent is used by applications which want to launch the dialer to make a phone call. The Intent Filter used to capture this action should be both default and browsable (to support dial requests from the browser), and must specify the tel: schema to replace existing dialer functionality (though it can support additional schemes).
> Intent.ACTION_VIEW The view action is used by applications wanting to view a piece of data. Ensure that the Intent Filter specifies the tel: schema to allow your new Activity to be used to view telephone numbers.
The following manifest snippet shows an Activity with Intent Filters that will capture each of these actions.
<action android:name="android.intent.action.CALL_BUTTON" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.DIAL" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="tel" /> </intent-filter> </activity>
Once your application has been started, it is up to you to allow users to enter or modify the number to call and initiate the outgoing call.
The simplest technique is to use the existing telephony stack. In this case you can use the Intent.ACTION_CALL action to initiate a call using the standard in-call Activity and letting the system handle the dialing, connection, and voice handling. Your application must have the call_phone uses-permission to broadcast this action.
Alternatively, you can completely replace the outgoing telephony stack by implementing your own dialing and voice handling framework. This is the perfect alternative if you are implementing a VOIP (voice over IP) application. Note that the implementation of an alternative telephony platform is beyond the scope of this book.
Note also that you can intercept these Intents to modify or block outgoing calls as an alternative to completely replacing the dialer screen.
Was this article helpful?
Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.