본문 바로가기

Android

call logs

http://www.anddev.org/video-tut_-_querying_and_displaying_the_calllog-t169.html


<?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.010 seconds, using GeSHi 1.0.8.4



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.171 seconds, using GeSHi 1.0.8.4

'Android' 카테고리의 다른 글

acessing call logs  (0) 2013.10.08
open call list  (0) 2013.10.08
browser open  (0) 2013.10.08
get phone number  (0) 2013.10.08
show the application manager  (0) 2013.10.08