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

Goto page 1, 2  Next
 
       anddev.org - Android Development Community | Android Tutorials | Index -> Novice Tutorials
Author Message
plusminus
Site Admin
Site Admin


Joined: 14 Nov 2007
Posts: 2655
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

_________________
Download my apps Idea
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: 2655
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

_________________
Download my apps Idea
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: 7

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: 7

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: 7

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:  28559 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: 3
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
trushal
Once Poster
Once Poster


Joined: 09 Jan 2009
Posts: 1

PostPosted: Tue Jan 13, 2009 1:16 pm    Post subject: Call Log Action ??? Reply with quote

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

i simply want to access call log in back end app ...

thank u in advance .......

_________________
TRUSHAL PATEL
Soft.Dev
Back to top
View user's profile Send private message
iPaul Pro
Developer
Developer


Joined: 15 Mar 2009
Posts: 29

PostPosted: Mon Mar 16, 2009 1:25 am    Post subject: Help Reply with quote

I've been stuck on this for hours. I'm new to Java and Android. I'd like to make an app that displays a list of missed calls (for personal purposes). I tried to implement this code but have had no luck. I even built the package with the example names. These are the errors I receive:

DateUtils cannot be resolved
R.drawable.in cannot be resolved
R.drawable.missed cannot be resolved
R.drawable.out cannot be resolved
The import android.util.DateUtils cannot be resolved
The method first() is undefined for the type Cursor
The method next() is undefined for the type Cursor
The method isSelectable(int) is undefined for the type BaseAdapter
The method compareTo(IconifiedText) of type IconifiedText must override a superclass method

I literally have all of the same code and files from this tutorial and the IconifiedText tutorial in my package.

Please help! Anyone
Back to top
View user's profile Send private message Visit poster's website
iPaul Pro
Developer
Developer


Joined: 15 Mar 2009
Posts: 29

PostPosted: Tue Mar 17, 2009 3:44 pm    Post subject: Reply with quote

I really don't know what I'm doing, so I wouldn't suggest following my instruction unless verified by someone else:

I have removed all of the errors in Osborns code, and I can actually try out the app now (yay!), but alas, it does nothing. I'm going to learn to debug and report back. But in the mean time, figured I'd share how I got it 'working'.

Okay, so I removed the DateUtils stuff altogether. Couldn't figure it out.
My mistake - forgot to copy the icons to 'res/layout' (r.drawables fixed)
first() should be isFirst()
next() should be moveToNext()
Remove the "super" from in front of isSelectable (replace with "this")
remove @Override for IconifiedText


Last edited by iPaul Pro on Wed Mar 25, 2009 4:03 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
iPaul Pro
Developer
Developer


Joined: 15 Mar 2009
Posts: 29

PostPosted: Mon Mar 23, 2009 1:37 pm    Post subject: Reply with quote

I got it working!

using all of my corrections from above, EXCEPT:

isFirst() should be moveToFirst()

Now, if anyone out there can a) give a hint as to how to further customize the views in the iconified list, or b) give an updated example with XML layout, that would be great.

Thanks


Last edited by iPaul Pro on Fri Apr 03, 2009 12:11 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
iPaul Pro
Developer
Developer


Joined: 15 Mar 2009
Posts: 29

PostPosted: Fri Mar 27, 2009 3:15 am    Post subject: Reply with quote

android.util.DateUtils is deprecated.

Does anybody have a good solution to replace:

Java:
String dateString = DateUtils.dateString(callDate).toString();


I tried:

Java:
long created = c.getLong(dateColumn);
Date date = new Date(created);
String dateString = DateUtils.formatDate(date);


and

Java:
long created = c.getLong(dateColumn);
Date date = new Date(created);
String dateString = DateFormat.getDateTimeInstance().format(date);


But this makes the app take a long time to load. This (loading) issue may be due to factors, other than using DateUtils and DateFormat - but I'm not sure. Any help or hints on speeding up Date parsing (or perhaps making it happen after the list fully loads) would be greatly appreciated.

Thanks.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Novice Tutorials All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
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.