Android Service System Services

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.