Site icon Craig Andrews

My First Android App: CallerID

I’ve been looking for an excuse to write an Android app, and those annoying “unknown number” phone calls presented themselves at the perfect problem to solve.
My CallerID application consists of two parts: a service that runs on a server and given a phone number returns the information associated with it, and an Android app that uses the service to display information to the user upon request or when the phone rings.

The service portion is licensed under the AGPLv3 so anyone can be automomous and run it themselves, instead of relying on my instance. I based the idea and some of the implementation, although not much of the original source is left, on CallerID Superfecta. It’s written in PHP, has pretty minimal requirements, and is easy to install – check out the source for the CallerID service on gitorious. In case you don’t want to install it yourself, you can use my instance, which the Android app uses by default. To query it, request URLs like this: http://callerid.integralblue.com/callerid.php?format=json&num=%28860%29%20429-7433 The service currently returns the listing name, company name (if applicable), and address in JSON format. The service can also just return the listing name, which is great for use with Asterisk, using URLs like this: http://callerid.integralblue.com/callerid.php?format=basic&num=%28860%29%20429-7433 To use this with Asterisk, make sure you have CURL support available, and modify your dialplan with a directive such as this one:
exten => _., n, Set(CALLERID(name)=${CURL(http://callerid.integralblue.com/callerid.php?format=basic&num=${CALLERID(num)})})

The Android application is written in Java, licensed under the GPLv3, and is available on the Google Android Market and (hopefully) soon on the Amazon Market and f-droid. The Android app source code is also available on gitorious. The application requires at least Android 1.5 – and supporting Android 1.5 all the way to 2.3 was an interesting experience, especially in the area of the Contacts API. It uses OpenStreetMaps (osmdroid) for maps (instead of Google Maps, as not every device has Google Maps, and Google Maps is not Free Software) and roboguice as an application framework.

I initially built the app using ant, like most Android apps, but decided to switch to using Maven for a few reasons:

I used the maven-android-plugin as a key component of the build process. If you’re starting an Android project, I highly recommend you check it out.

To build the app:

  1. Install the Android SDK (you’ll need at least SDK versions 3 and 10)
  2. Set the ANDROID_HOME environment variable as described on the maven-android-plugin Getting Started page
  3. Install Maven (Windows and Mac installers are available for download, and it’s packaged for most Linux distributions)
  4. Install Git (Windows and Mac installers are available for download, and it’s packaged for most Linux distributions)
  5. git clone git://gitorious.org/callerid-for-android/mainline.git mainline
  6. cd mainline/application
  7. mvn clean install
  8. Since osmdroid is not in the Maven repository, you’ll need to manually install it. These directions can also be found in application/pom.xml:
    1. wget http://osmdroid.googlecode.com/files/osmdroid-android-3.0.3.jar
    2. mvn install:install-file -DgroupId=org.osmdroid -DartifactId=osmdroid -Dversion=3.0.3 -Dpackaging=jar -Dfile=osmdroid-android-3.0.3.jar
  9. mvn clean install (again) – it should succeed

The apk is located at “mainline/application/target/callerid-1.0-SNAPSHOT.apk”

These steps do not perform the integration tests. If you want to run those, in the step above that says “cd mainline/application” run “cd mainline” instead. Note that you’ll either have to have your Android phone plugged in to your computer (and running in debug mode, recognized by adb) or an Android emulator running.

To create a ready-to-release apk, which includes running proguard, zipalign, and jarsign, run this command from the “mainline” directory: mvn clean install -Prelease -Dsign.keystore=/home/candrews/projects/callerid/test-key.keystore -Dsign.alias=mykey -Dsign.storepass=testtest -Dsign.keypass=testtest Note that this command will sign using the test key. If you really want to distribute the apk, you’ll need to generate your own key using keytool. In either case, the ready to distribute apk is located at “mainline/application/target/callerid-1.0-SNAPSHOT-signed-aligned.apk”

If you want to develop the application using Eclipse, first make sure that you can successfully compile the application using the steps above. Then you need to install some Eclipse plugins:

From Eclipse:

  1. Select File-Import…
  2. Maven, Existing Maven Projects
  3. The Root Directory is the “mainline” directory you checked out from git
  4. Finish
  5. You should now have 3 projects in your Eclipse workspace: callerid, callerid-it, and callerid-parent
  6. For the “callerid” and “callerid-it” project, modify the Build Path by right clicking on the project, selecting “Build Path” then “Configure Build Path.” You need to remove “JRE System Library” and then click “Add Library” “Android Classpath Container” (see https://code.google.com/a/eclipselabs.org/p/m2eclipse-android-integration/issues/detail?id=41)
  7. That’s it – Eclipse should automatically build as you go, and you can use the Eclipse/Android development tools just as everyone else does.

I hope both the server portion and application portion are reasonably easy to run, build, and understand. If you have any questions or concerns, please comment – and contributions are of course very welcome to both projects!
Please note that this project is not in any way related to my employer – it is a completely personal, non-work project. This article has been cross-posted to Isobar’s blog.

My First Android App: CallerID by Craig Andrews is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Exit mobile version