hi megha, thanks for all your help - just one little problem and its done.
the cursor seems to be working now - BUT the last thing is that i need to send data to my service and i dont seem to have conquered that although i have tried various things. i guess i dont understand it.... here is the code for the intent receiver that calls the service, and the service package org.apache.android.mailContactsOften; import android.content.Context; import android.content.Intent; import android.content.IntentReceiver; import android.os.Bundle; public class EmailContactsRepeat extends IntentReceiver { @Override public void onReceiveIntent(Context context, Intent intent) { //get bundle of extras (userid, passwork, email) from intent String userid = intent.getStringExtra("userid"); String password = intent.getStringExtra("password"); String email = intent.getStringExtra("email"); int foo=0; int rbutton = intent.getIntExtra("rbutton", foo); String body = intent.getStringExtra("body"); //context.startService(new Intent(context, GetContacts.class), // null); Intent conintent = new Intent(context, GetContacts.class); //bundle data for conintent // bundle extras (data) with the intent. //conintent.putExtra("userid", userid); //conintent.putExtra("password", password); //conintent.putExtra("email", email); //conintent.putExtra("body",body); Bundle b= new Bundle(); b.putString("userid", userid); b.putString("password", password); b.putString("email", email); b.putString("body",body); context.startService(conintent,b); } } here is the service package org.apache.android.mailContactsOften; import org.apache.android.mailContactsOften.GetContacts; import android.app.Service; import android.database.Cursor; import android.os.Binder; import android.os.IBinder; import android.os.Parcel; import android.content.Intent; import android.os.Bundle; public class GetContacts extends Service { String pList = ""; String st = ""; String userid =""; String password=""; String email ="@gmail.com"; String body; void onStart(Intent in, Bundle b) { userid = b.getString("userid"); password = b.getString("password"); email = b.getString("email"); body = b.getString("body"); } @Override protected void onCreate() { Thread thr = new Thread(null, mTask, "GetContacts"); thr.start(); } /** * The function that runs in our worker thread */ Runnable mTask = new Runnable() { public void run() { // Normally we would do some work here... // get the contact string and call send to send the info body = getContactStr(); // send the data SendContacts s = new SendContacts (body,userid, password, email); // Done with our work... stop the service! GetContacts.this.stopSelf(); } }; @Override public IBinder onBind(Intent intent) { return mBinder; } /** * This is the object that receives interactions from clients. See RemoteService * for a more complete example. */ private final IBinder mBinder = new Binder() { @Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) { return super.onTransact(code, data, reply, flags); } }; public String getContactStr() { pList = ""; st = ""; Cursor c = getContentResolver().query( android.provider.Contacts.Phones.CONTENT_URI, null, null, null, android.provider.Contacts.Phones.PERSON_ID+ " ASC"); //startManagingCursor(c); // Retrieve the column-indixes of phoneNumber, name and type int numberColumn = c.getColumnIndex(android.provider.Contacts.Phones.NUMBER); int nameColumn = c.getColumnIndex(android.provider.Contacts.Phones.NAME); // type can be: home, cell, etc (number provided - must be interpreted int typeColumn = c.getColumnIndex(android.provider.Contacts.Phones.TYPE); int labelColumn = c.getColumnIndex(android.provider.Contacts.Phones.LABEL); // Will hold the calls, available to the cursor // Loop through all entries the cursor provides to us. if(c.first()){ do{ String callerPhoneNumber = c.getString(numberColumn); String pname = c.getString(nameColumn); int pType = c.getInt(typeColumn); String label = c.getString(labelColumn); if (label != null) st = label; else st = getPhoneType(pType); pList = pList + "\n"+ pname + " "+ st + "\t # " + callerPhoneNumber +" " ; }while(c.next()); } c.close(); if (pList == "") return ("No Contacts in Cell Phone "); else return pList; } private String getPhoneType(int p) { String st = ""; switch(p) { case android.provider.Contacts.Phones.HOME_TYPE: st = "Home"; break; case android.provider.Contacts.Phones.HOME_FAX_TYPE: st = "HomeFax"; break; case android.provider.Contacts.Phones.MOBILE_TYPE: st = "Cell"; break; case android.provider.Contacts.Phones.WORK_TYPE: st = "Work"; break; case android.provider.Contacts.Phones.OTHER_TYPE: st = ""; break; case android.provider.Contacts.Phones.WORK_FAX_TYPE: st = "WorkFax"; break; case android.provider.Contacts.Phones.PAGER_TYPE: st = "Pager"; break; } return st; } } On Apr 14, 5:40 pm, "Megha Joshi" <[EMAIL PROTECTED]> wrote: > Hi, > > This is because the startManagingCursor() method is not present in Service > class, it can only be used for Activity. > > You don't need this method in service, you can simply use the cursor, and > be careful about closing it with cursor.close() when you are done. > > Thanks, > Megha --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new M5 SDK! http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---