Android PhoneGap Plugin for Twilio Client


I recently got the chance to help out another developer (BetterVoicemail.com) by developing an open source PhoneGap/Cordova plugin for the Twilio Client SDK. If you’re not familiar with Twilio Client, it’s a Voice-over-IP (VoIP) library for web, iOS, and Android that lets you build web pages and mobile apps that can make outgoing phone calls, receive phone calls, chat through the browser, and all kinds of other interesting projects.

One of the interesting things about its implementation is that the JavaScript web Twilio Client SDK does not currently work on either Android or iOS web browsers. This means that to have voice-enabled mobile applications, you need to use the iOS or Android SDK’s. Those are written for developers using the native languages of the platform - either Objective-C, or Android - so it’s not really very easy to have a cross-platform solution.

One way to bridge this gap is to use PhoneGap to build your applications in HTML5/CSS/JavaScript - Steve Graham had built a PhoneGap Plugin for the Twilio Client for iOS at https://github.com/stevegraham/twilio_client_phonegap that shared the same Javascript API as the Twilio web client. There wasn’t an Android implementation, so it wasn’t truly cross-platform.

The first thing I did was to bring the current iOS code base up to PhoneGap 2.9 compatibility - PhoneGap moves quickly and breaks existing plugins, though they do publish a plugin upgrade guide to follow. After using that as a base, I built a test iOS PhoneGap app that exercised the iOS plugin, because the idea was that the Android plugin would work identically to the iOS plugin.

The Twilio Android Client SDK doesn’t have the same API as the iOS version - in particular, to handle incoming calls, you need to construct a PendingIntent for the Twilio Client SDK to fire off, instead of just registering a delegate with the SDK. So for the Android plugin to work, you need to add an activity to your Android manifest XML file. I used the LocalBroadcastManager to communicate with the plugin, so I could implement a listener that worked exactly like the iOS version. You’ll also need to follow the Twilio Client for Android installation instructions (after using PhoneGap/Cordova to generate your project), which are more complicated than the Twilio Client for iOS installation instructions.

If you want to use the  Twilio Client plugin for PhoneGap for Android or iOS, it hasn’t yet been merged back into the original repo yet - so clone it from my GitHub for the time being: (https://github.com/jefflinwood/twilio_client_phonegap)