Home > Uncategorized > My First Android App: CallerID

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:

  • Maven manages dependencies, so I don’t need to include large binaries in the source repository.
  • Using a Maven multimodule approach, I can have a separate integration testing project (application-it) and application project (application), making automatic testing easy.
  • I’ve used Maven for a number of projects in the past, and find it easy and sufficiently “magic” (but not overly so), compared to ant, which I find too “low level.”
  • Maven automatically will run proguard (for optimization, not obfuscation), zipalign, and signing when given a “release” profile, or skip those steps when running under the default profile.

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.

Creative Commons License
My First Android App: CallerID by Craig Andrews, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

Categories: Uncategorized Tags: , , , ,
  1. Sharad
    May 4th, 2011 at 10:58 | #1
    Is there a database of known spam-callers that we could add? Would be great if those unknown numbers were tagged. Since they may have a name from your regular database query, maybe we could color them in RED or something?
    • May 5th, 2011 at 12:18 | #2
      There are a number of such databases (some are country specific, some not). I intend to add support for just such a feature, including the ability to simply ignore calls that come from known spammers (assuming the platforms allows such call blocking… we’ll see).

      Contributions are welcome, of course, if you don’t want to wait :-)

  2. Jeroen
    June 1st, 2012 at 07:45 | #3
    Hi,

    First of all, thanks for this wonderful project.

    You don’t list the Netherlands as supported, but you do have The Netherlands in the drop down menu on the Caller ID web service. However, it doesn’t seem to work on any phone number I know, both local and landline. Are you planning on adding support for The Netherlands any time soon?

  3. June 1st, 2012 at 10:22 | #4
    @Jeroen
    Unfortunately, for now, all I can do is tell you that the phone number is from the Netherlands.

    I can’t find any web sites that will perform reverse number lookup for the Netherlands (given a phone number, return who owns it). If can find one, let me know and I’ll gladly add support for it as quickly as I can (probably within a couple of days).

  4. Ernest
    June 5th, 2012 at 04:28 | #5
    Cool idea, although those of us on a CDMA network (Verizon and Sprint) lose our internet access during an incoming call. :(
  5. Jeff
    June 6th, 2012 at 00:03 | #6
    Craig,
    Great App. I Have one question
    It would be nice to also open up a browser window and display a page based upon the caller id I tried to add to your HttpCallerIDLookup.java

    something like

    final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(“http://www.myurl.com/index.php?action=getCallerInformation&number=phoneNumber.toString()”));
    this.startActivity(intent);

    but it will not compile.

  6. June 13th, 2012 at 11:07 | #7
    @Ernest
    Actually, if you’re a Verizon/Sprint/any CDMA network user and your phone has LTE service, then you won’t lose Internet access during a call any more. So you have that to look forward to :-)

    I’m also working on an update that will lookup the incoming call’s location offline (which will work nicely for the non-LTE CDMA users). I plan on displaying this offline information until the online lookup completes so at least you get geographical information.

  1. No trackbacks yet.