I am using android SDK1.5 r_1.I am querying the callLog for call
history!!!
problem
here is my code!!!!!!!!!!!!!
package com.arka.CallLogDemo;
//import java.sql.Date;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
//import android.text.format.DateFormat;
//import android.text.format.DateUtils;
public class CallLogDemo extends ListActivity {/* ListActivity is a
Activity that display items by binding it to a data source such as a
cursor or array
and exposes event handlers when users select them*/
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
callDialog("start");
// Querying for a cursor is like querying for any SQL-Database
Cursor c = getContentResolver().query(/*Cursor interface
provides random read-write access to the result set returned by a
database query.*/
android.provider.CallLog.Calls.CONTENT_URI,//which
dataset
null, null, null,
android.provider.CallLog.Calls.DATE + " DESC");//
ordered by
startManagingCursor(c);/*A managed Cursor handles all of the
niceties, such as unloading itself when the activity pauses, and
requerying itself when the activity restarts*/
// Retrieve the column-indexes 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);
callDialog("start Arraylist");
// Will hold the calls, available to the cursor
ArrayList<IconifiedText> callList = new
ArrayList<IconifiedText>();
callDialog("created Arraylist");
//Boolean flag=c.moveToFirst();
// Loop through all entries the cursor provides to us.
/*if (flag==true)
callDialog("true");
else
callDialog("false");
callDialog("count "+c.getPosition());*/
if(c!=null)
{
callDialog("not null");
if(!c.moveToFirst())//**********ERROR******always returning
false!!!!!!!!!!!!!!
do{
String callerPhoneNumber = c.getString
(numberColumn);
//int callDate = c.getInt(dateColumn);*************
int callType = c.getInt(typeColumn);
callDialog("before case");
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;
}
callDialog("after case");
// Convert the unix-timestamp to a readable
datestring
String dateString=c.getString(dateColumn);
//String dateString = DateUtils.dateString
(callDate).toString();
/* long created = c.getLong(dateColumn);
Date date = new Date(created);
String dateString = DateUtils.formatDate(date);*/
callList.add(new IconifiedText("@ " + dateString
+ " | # " + callerPhoneNumber,
currentIcon));
}while(c.moveToNext());
//}
// Create an ListAdapter that manages to display out
'callList'
IconifiedTextListAdapter itla = new IconifiedTextListAdapter
(this);
itla.setListItems(callList);
this.setListAdapter(itla);
// Done =)
}
}
public void callDialog(CharSequence message )
{
final AlertDialog.Builder a=new AlertDialog.Builder(this);
a.setMessage(message);
a.setTitle("HelloAndroid");
//a.wait(2000);
a.setPositiveButton("close", new
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int whichButton)
{
//a.setCancelable(true);
}
});
a.show();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---