The Android SDK provides a lot of common services, i.e. system services, where developers can get the specified service through the Getsystemservice method of the Activity class. System services include audio services, video Services window services, and so on. This article mainly speaks Telephony_service. This service is used to monitor the status of a call.
1. Get the Telphony_mannager object
Telephonymanager tm= (Telephonymanager) Getsystemservice (Context.telephony_service);
Myphonecalllistener listener=new Myphonecalllistener ();
Tm.listen (Listener, phonestatelistener.listen_call_state);
Gets the TM object and implements the listener for that object
2. Define the Listening method
1 Public classMyphonecalllistenerextendsphonestatelistener{2 Public voidOncallstatechanged (intstate,string Incomingnae)3 {4 Switch(state)5 {6 CaseTelephonymanager.call_state_offhook:7Toast.maketext (mainactivity. This, "in the middle of a call ... ", Toast.length_long). Show ();8 Break;9 Casetelephonymanager.call_state_ringing:TenToast.maketext (mainactivity. This, Incomingnae, Toast.length_long). Show (); One Break; A } - Super. oncallstatechanged (State, Incomingnae); - } the}Myphonelistener
Custom Listener methods.
Android Service System Services