andbook!.pdf - Learning Android Get an anddev.org - Android-Shirt Back to index
anddev.org Header Logo
FAQ Search Top rated articles Browse Feeds anddev.org - Authors Contact Details Register Log in

[VIDEO-Tut] - Querying and Displaying the CallLog


 
       anddev.org - Android Development Community | Android Tutorials | Index -> Novice Tutorials
Author Message
plusminus
Site Admin
Site Admin


Joined: 14 Nov 2007
Posts: 2439
Location: College Park, MD

PostPosted: Sat Dec 01, 2007 8:25 pm    Post subject: [VIDEO-Tut] - Querying and Displaying the CallLog Reply with quote

[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 Smile

Idea Read Before: Iconified List - The making of !

What it will look like:
Filesize: 10 MBytes Exclamation


The Full Source:
Do not forget:
Arrow The little Icons for Incoming/Outgoing/Missed
Arrow The source of the Iconified List Exclamation


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 Question

_________________
Please remember, that this board is give & take Smile

| Android Development Community / Tutorials
Back to top
View user's profile Send private message Send e-mail Visit poster's website
alonav
Freshman
Freshman


Joined: 07 Mar 2008
Posts: 4

PostPosted: Fri Mar 07, 2008 6:15 pm    Post subject: Need some help on the call log Reply with quote

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
View user's profile Send private message
alonav
Freshman
Freshman


Joined: 07 Mar 2008
Posts: 4

PostPosted: Sat Mar 08, 2008 12:02 am    Post subject: activity class does not exist? Reply with quote

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
View user's profile Send private message
plusminus
Site Admin
Site Admin


Joined: 14 Nov 2007
Posts: 2439
Location: College Park, MD

PostPosted: Sat Mar 08, 2008 5:25 pm    Post subject: Reply with quote

Hello alonav,

btw: you should work with JDK 1.6 instead of 1.5 !

You need to adopt the AndroidManifest.xml-File:
XML:
package="your.complete.package.path.to.the.activity">

XML:
<activity class=".NAMEOFYOURACTIVITYHERE" android:label="@string/app_name">


Regards,
plusminus

_________________
Please remember, that this board is give & take Smile

| Android Development Community / Tutorials
Back to top
View user's profile Send private message Send e-mail Visit poster's website
alonav
Freshman
Freshman


Joined: 07 Mar 2008
Posts: 4

PostPosted: Wed Mar 12, 2008 8:20 pm    Post subject: ActivityManager: Error: Activity class {CallLogDisplayer/Cal Reply with quote

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
View user's profile Send private message
gzhhong
Freshman
Freshman


Joined: 19 May 2008
Posts: 5

PostPosted: Mon May 19, 2008 2:05 pm    Post subject: can we initiate the recent call application? Reply with quote

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
View user's profile Send private message
gzhhong
Freshman
Freshman


Joined: 19 May 2008
Posts: 5

PostPosted: Mon May 19, 2008 3:59 pm    Post subject: a quickly method to show Reply with quote

Intent i = new Intent();
i.setAction(Intent.VIEW_ACTION);
i.setData(new ContentURI("content://call_log/calls"));
startActivity(i);
Back to top
View user's profile Send private message
gzhhong
Freshman
Freshman


Joined: 19 May 2008
Posts: 5

PostPosted: Tue May 20, 2008 2:30 pm    Post subject: how to list the missed call only Reply with quote

Another question is how to filter the missed call log by the content uri?
Back to top
View user's profile Send private message
xsuo
Freshman
Freshman


Joined: 21 May 2008
Posts: 4

PostPosted: Thu May 22, 2008 7:45 am    Post subject: Re: [VIDEO-Tut] - Querying and Displaying the CallLog Reply with quote

problem:

java.lang.SecurityException:
permission

android.permission.READ_CONTACTS required for provider
call_log.



1.jpg
 Description:
 Filesize:  41.73 KB
 Viewed:  7243 Time(s)

1.jpg


Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
myandroid
Freshman
Freshman


Joined: 08 Jul 2008
Posts: 2
Location: china

PostPosted: Thu Jul 31, 2008 2:34 am    Post subject: How to apply ScrollView to your IconifiedList Reply with quote

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
View user's profile Send private message
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Novice Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


© 2007, Android Development Community
All rights reserved.
Powered by phpBB.