Actually I was thinking, would a service be the way to go? Because won't my app start(or do what I want it to) if I use the PhoneState Listener?
On May 25, 11:05 am, GT <[email protected]> wrote: > Ok, Ive fixed that and added more stuff. Just so you know where I am > at here is some more code im still working on it, and thank you so > much for your help. > > import android.app.Service; > import android.content.Context; > import android.content.Intent; > import android.os.IBinder; > import android.telephony.PhoneStateListener; > import android.telephony.TelephonyManager; > > public class incomingCallService extends Service > { > @Override > public void onCreate() > { > //Actions to do when Service is created > String srvcName = Context.TELEPHONY_SERVICE; > TelephonyManager telephonyManager = (TelephonyManager) > getSystemService(srvcName); > PhoneListener phoneListener = new PhoneListener(); > telephonyManager.listen(phoneListener, > PhoneStateListener.LISTEN_CALL_STATE); > } > > @Override > public IBinder onBind(Intent intent) > { > //Replace with service binding implementation. > return null; > } > > @Override > public void onStart(Intent intent, int StartId) > { > } > > public class PhoneListener extends PhoneStateListener > { > public void onCallStateChnaged(int state, int incomingNumber) > { > switch(state) > { > case TelephonyManager.CALL_STATE_IDLE: > break; > case TelephonyManager.CALL_STATE_OFFHOOK: > break; > case TelephonyManager.CALL_STATE_RINGING: > findContactNum(incomingNumber); > break; > } > } > public void findContactNum(int number) > { > //Find contanct > } > } > > } > > On May 25, 10:42 am, GT <[email protected]> wrote: > > > > > Ok thank you, I will mess around with that then > > > On May 25, 5:03 am, Mark Murphy <[email protected]> wrote: > > > > GT wrote: > > > > I just quite don't understand how to use the two... > > > > > This is what I have so far, am I even on the right track? And I do > > > > appreciate the response... > > > > <snip> > > > > > @Override > > > > public void onStart(Intent intent, int StartId) > > > > { > > > > String srvcName = Context.TELEPHONY_SERVICE; > > > > TelephonyManager telephonyManager = (TelephonyManager) > > > > getSystemService(srvcName); > > > > } > > > > Depending on how you are using your service, you may want to get your > > > TelephonyManager and use it in onCreate(). onStart() can be called > > > several times; onCreate() is only called once before a corresponding > > > onDestroy(). If you only need one listener for the service -- and you > > > should only need one -- I'd register it via TelephonyManager#listen() on > > > onCreate() and release it in onDestroy(). > > > > > public class PhoneListener extends PhoneStateListener > > > > { > > > > > } > > > > You could use a few methods here, but I suspect you realize that. > > > > -- > > > Mark Murphy (a Commons > > > Guy)http://commonsware.com|http://twitter.com/commonsguy > > > > _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" 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-developers?hl=en -~----------~----~----~----~------~----~------~--~---

