Getting the Contact Info when on a number

Public on January 31, 2009
On android when someone call you or you receive a message, a non formatted number would be shown to you and for you to find out whom that number is, you have to use Contacts.Phones.CONTENT_FILTER_URL on your query. This article is based on Get Phone State When Someone is calling using BroadcastReceiver Example

public class MyPhoneStateListener extends PhoneStateListener {
  private String[] projection = new String[] {
    People._ID, People.NAME, People.NUMBER
  public void onCallStateChanged(int state,String incomingNumber){
      case TelephonyManager.CALL_STATE_IDLE:
        Log.d("DEBUG", "IDLE");
      case TelephonyManager.CALL_STATE_OFFHOOK:
      case TelephonyManager.CALL_STATE_RINGING:
        Log.d("DEBUG", "RINGING");
  public void handleCall(String incomingCall){
    Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, incomingNumber);
    contactsCursor = context.getContentResolver().query(contactUri, projection, null , null, People.NAME + " ASC");
      int phoneNameIndex = contactsCursor.getColumnIndex(People.NAME);
      String phoneNameStr = contactsCursor.getString(phoneNameIndex);
      Log.d("DEBUG",phoneNameStr + " is calling");
      Log.d("DEBUG","Not a contact");

Quick Explanation
Looking on the handleCall function, there is nothing really new here, for the BroadcastReceiver explanation go to this page and for the displaying contact names go to this page. Sorry i'm too lazy to explain here coz i already explained it on the previous post.

Anyway i have to temporarily stop my android adventure and do some stuff for work which is webbased stuff so the next article would be web based article. Thanks

Update History
   Jan 17, 2012 - Visual Update

[Advertising]Faster Thinking - Speed up your brain

Faster Thinking Game

sentiment_satisfied Emoticon