What you learn: You will learn how to query for the CallLog using a Cursor and display all Incoming/Outgoing/Missed calls in an IconifiedList.
Difficulty: 1.5 of 5
What it will look like:
[align=center] Filesize: 10 MBytes
[/align]
The Full Source:
Do not forget:
AndroidManifest.xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.anddev.android.calllogdisplayer">
- <uses-permission id="android.permission.READ_CONTACTS"/>
- <application android:icon="@drawable/icon">
- <activity class=".CallLogDisplayer" android:label="@string/app_name">
- <intent-filter>
- <action android:value="android.intent.action.MAIN" />
- <category android:value="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
/src/your_package_structure/CallLogDisplayer.java
Using java Syntax Highlighting
- package org.anddev.android.calllogdisplayer;
- import java.util.ArrayList;
- import org.anddev.android.calllogdisplayer.iconifiedlist.IconifiedText;
- import org.anddev.android.calllogdisplayer.iconifiedlist.IconifiedTextListAdapter;
- import android.app.ListActivity;
- import android.database.Cursor;
- import android.graphics.drawable.Drawable;
- import android.os.Bundle;
- import android.util.DateUtils;
- public class CallLogDisplayer extends ListActivity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- // Querying for a cursor is like querying for any SQL-Database
- Cursor c = getContentResolver().query(
- android.provider.CallLog.Calls.CONTENT_URI,
- null, null, null,
- android.provider.CallLog.Calls.DATE + " DESC");
- startManagingCursor(c);
- // Retrieve the column-indixes of phoneNumber, date and calltype
- int numberColumn = c.getColumnIndex(
- android.provider.CallLog.Calls.NUMBER);
- int dateColumn = c.getColumnIndex(
- android.provider.CallLog.Calls.DATE);
- // type can be: Incoming, Outgoing or Missed
- int typeColumn = c.getColumnIndex(
- android.provider.CallLog.Calls.TYPE);
- // Will hold the calls, available to the cursor
- ArrayList<IconifiedText> callList = new ArrayList<IconifiedText>();
- // Loop through all entries the cursor provides to us.
- if(c.first()){
- do{
- String callerPhoneNumber = c.getString(numberColumn);
- int callDate = c.getInt(dateColumn);
- int callType = c.getInt(typeColumn);
- Drawable currentIcon = null;
- switch(callType){
- case android.provider.CallLog.Calls.INCOMING_TYPE:
- currentIcon = getResources().getDrawable(R.drawable.in);
- break;
- case android.provider.CallLog.Calls.MISSED_TYPE:
- currentIcon = getResources().getDrawable(R.drawable.missed);
- break;
- case android.provider.CallLog.Calls.OUTGOING_TYPE:
- currentIcon = getResources().getDrawable(R.drawable.out);
- break;
- }
- // Convert the unix-timestamp to a readable datestring
- String dateString = DateUtils.dateString(callDate).toString();
- callList.add(new IconifiedText("@ " + dateString
- + " | # " + callerPhoneNumber, currentIcon));
- }while(c.next());
- }
- // Create an ListAdapter that manages to display out 'callList'
- IconifiedTextListAdapter itla = new IconifiedTextListAdapter(this);
- itla.setListItems(callList);
- this.setListAdapter(itla);
- // Done =)
- }
- }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4
Regards,
plusminus
PS: I could not figure out, why the calls happened in December. Someone has seen the default-date of the emulator




what is the <action> for Listening Call Log change event ??

