| Author |
Message |
plusminus Site Admin


Joined: 14 Nov 2007 Posts: 2439 Location: College Park, MD
|
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
_________________
Please remember, that this board is give & take 
| 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: 2439 Location: College Park, MD
|
|
| 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 |
|
 |
gzhhong Freshman

Joined: 19 May 2008 Posts: 5
|
Posted: Mon May 19, 2008 2:05 pm Post subject: can we initiate the recent call application? |
|
|
I think the most effiective way to show the missed calls is to initiate the recent call application of android.
There are a table named calls in the contacts database and the calllog is a content provider named content.provider.calllog.calls.
Maybe a effective way is like below:
Intent i = new Intent();
i.setAction(Intent.VIEW_ACTION);
i.setData(new ContentURI("content://xxxxxxxx"));
startActivity(i);
if we can provide the correct uri in setData, maybe we can show the missed call logs in the recent calls application, right?
The question is: what is the correct uri?
|
|
| Back to top |
|
 |
gzhhong Freshman

Joined: 19 May 2008 Posts: 5
|
Posted: Mon May 19, 2008 3:59 pm Post subject: a quickly method to show |
|
|
Intent i = new Intent();
i.setAction(Intent.VIEW_ACTION);
i.setData(new ContentURI("content://call_log/calls"));
startActivity(i);
|
|
| Back to top |
|
 |
gzhhong Freshman

Joined: 19 May 2008 Posts: 5
|
Posted: Tue May 20, 2008 2:30 pm Post subject: how to list the missed call only |
|
|
| Another question is how to filter the missed call log by the content uri?
|
|
| Back to top |
|
 |
xsuo Freshman

Joined: 21 May 2008 Posts: 4
|
Posted: Thu May 22, 2008 7:45 am Post subject: Re: [VIDEO-Tut] - Querying and Displaying the CallLog |
|
|
problem:
java.lang.SecurityException:
permission
android.permission.READ_CONTACTS required for provider
call_log.
| Description: |
|
| Filesize: |
41.73 KB |
| Viewed: |
7243 Time(s) |

|
|
|
| Back to top |
|
 |
myandroid Freshman


Joined: 08 Jul 2008 Posts: 2 Location: china
|
Posted: Thu Jul 31, 2008 2:34 am Post subject: How to apply ScrollView to your IconifiedList |
|
|
hello,plusminus
How to apply ScrollView to your IconifiedList
i try it like this in layout.xml and init the list in Activity's onCreate function
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
But i got an error:list views can't have unspecified size
can you help me to see it,thanks
_________________ Do my best to do everything |
|
| Back to top |
|
 |
|