Read call logs of android using Python

This blog is just to give you introduction about reading call logs in sl4a and play with the call log data.
Before proceeding to this tutorial I assume you know about sl4a and python in android and you install "adb tool" in your PC and connected your android device to PC or you can also write following program directly in your phone and run it.
We will create simple program in python which will read call logs.
  1. Python program for reading call logs
    import android
    
    # once we have "droid" object we have whole power to control your android phone. :)
    droid = android.Android()
    
    # This is URI for reading call logs
    query = "content://call_log/calls"
    
    # Query Android db to get call logs
    call_log_data = droid.queryContent(query)
    
    # get result from call_log query
    call_log_result = call_log_data.result
    
    # Just print one record to get idea what each row represent
    
    print call_log_result[0]
  2. Create file called "read_call_logs.py" and add above code in it.
  3. Now run the program using following command
    "python read_call_logs.py"
  4. I got following output (you may get different output based on your call log data)
    {u'geocoded_location': u'India', u'photo_id': u'2104', u'name': u'Aamir Khan', u'countryiso':
    u'IN', u'numbertype': u'2', u'lookup_uri':
    u'content://com.android.contacts/contacts/lookup/925ida597d60fd8f669.3789r687-4927354F3D57272D2751.2142i285/286',
    u'formatted_number': u'+91 11 99 846546', u'number': u'+911199846546', u'presentation': u'1',
    u'normalized_number': u'+918149846546', u'duration': u'119', u'date': u'1410590024288', u'new':
    u'0', u'_id': u'674', u'type': u'1'}
  5. Description of each key and value of above dictionary is explained on android developer site. please refer
    http://developer.android.com/reference/android/provider/CallLog.Calls.html

Comments

Popular Posts