1. 2015 is going to be a great year for Android! Why wait??
    Samsung Galaxy Note 5 | Samsung Galaxy S6 | HTC One M9
  2. New Forum Created: Samsung Gear VR!

how to deal with classes in android? help please


  1. kwty

    kwty Member

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

Share This Page