| Author |
Message |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 1878 Location: Germany
|
Posted: Sat Dec 01, 2007 8:25 pm Post subject: [VIDEO-Tut] - Querying and Displaying the CallLog |
|
|
[VIDEO-Tut] - Querying and Displaying the CallLog
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
Read Before: Iconified List - The making of !
What it will look like:
Filesize: 10 MB ytes

The Full Source:
Do not forget:
The little Icons for Incoming/Outgoing/Missed
The source of the Iconified List
AndroidManifest.xml
| XML: | <?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> |
/src/your_package_structure/CallLogDisplayer.java
| Java: | 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 =)
}
} |
Regards,
plusminus
PS: I could not figure out, why the calls happened in December. Someone has seen the default-date of the emulator  _________________
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
alonav Freshman
Joined: 07 Mar 2008 Posts: 4
|
Posted: Fri Mar 07, 2008 6:15 pm Post subject: Need some help on the call log |
|
|
First of all that looks like a great example, but i can't make it work - i'm a bit new in java
line 49 in CallLogDisplayer class got an error:"R.drawable.in cannot be resolved"
line 52 in CallLogDisplayer class got an error:"R.drawable.missed cannot be resolved"
line 55 in CallLogDisplayer class got an error:"R.drawable.out cannot be resolved"
line 59 in IconifiedText class got an error: "The method compareTo(IconifiedText) of type IconifiedText must override a superclass method"
can i download the whole project from somewhere?
Please help!
THNX |
|
| Back to top |
|
 |
alonav Freshman
Joined: 07 Mar 2008 Posts: 4
|
Posted: Sat Mar 08, 2008 12:02 am Post subject: activity class does not exist? |
|
|
After fixing my previouse reply errors (i got rid of the @override of the compareto function) i'm getting another error after trying to run the project:
ActivityManager: Error: Activity class {CallLogDisplayer/CallLogDisplayer.CallLogDisplayer} does not exist.
Please help
THNX |
|
| Back to top |
|
 |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 1878 Location: Germany
|
|
| Back to top |
|
 |
alonav Freshman
Joined: 07 Mar 2008 Posts: 4
|
Posted: Wed Mar 12, 2008 8:20 pm Post subject: ActivityManager: Error: Activity class {CallLogDisplayer/Cal |
|
|
Hi again,
I updated the JDK to 1.6 & configured it in eclipse
the problem remains the same:
my package in XML file is package="CallLogDisplayer">
I can't write "class" like you wrote - i have an error on that
<activity android:name=".CallLogDisplayer" android:label="@string/app_name">
i can't write android:value either
so i wrote:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
THNX |
|
| Back to top |
|
 |
|