1. Check out our companion app, Forums for Android! Download from Google Play

how to deal with classes in android? help please

Discussion in 'Application Development' started by kwty, May 4, 2009.

  1. kwty

    kwty Member
    Thread Starter
    5

    Mar 4, 2009
    9
    0
    5
    Hi guys,
    I'm working in a project and I want to create a class that has a cursor to retrieve the call log or contacts data and passes them to the main activity or print them or doing anything with them. The problem is when I want to deal with the getContentResolver() and StartManagingCursor(Cursor) they gave me errors. When I do the same application inside the main activity it works fine with me. I tried to extends the activity in the class the error is gone but the program isn't work. I really need to run this application in a separate class and call it inside the main activity so how can I handle this problem ???

    The code is as the following:

    import java.io.IOException;
    import java.io_ObjectOutputStream;
    import java.net.Socket;

    import android.app.Activity;
    import android.database.Cursor;
    import android.os.Bundle;

    public class CallLog1 {

    private ObjectOutputStream out;
    public CallLog1(Socket clin) throws IOException{

    Socket client = clin;
    // 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


    // Loop through all entries the cursor provides to us.
    if(c.moveToFirst()){
    do{
    String callerPhoneNumber = c.getString(numberColumn);
    int callDate = c.getInt(dateColumn);
    int callType = c.getInt(typeColumn);

    String type = null;
    switch(callType){
    case android.provider.CallLog.Calls.INCOMING_TYPE:
    type = "Incoming Call";
    break;
    case android.provider.CallLog.Calls.MISSED_TYPE:
    type = "Missed Call";
    break;
    case android.provider.CallLog.Calls.OUTGOING_TYPE:
    type = "Outgoing Call";
    break;
    }
    .... bla bla bla

    How can I deal with the Cursor in this case ??

    With my best regards.
     

    Advertisement

Share This Page

Loading...