Android Lab Test : Managing the telephone calls (english)
Video of tutorial on : https://www.youtube.com/playlist?list=PLL2Z3bzdO25yHwIV3XdMzKs61At0Ldh6L
Visit http://www.AndroidLabTest.com
Presiding Officer Training module 2024 lok sabha elections
Android Lab Test : Managing the telephone calls (english)
1. Develop on Android
Android Lab Test
www.AndroidLabTest.com
Youku
By Bruno Delb
www.weibo.com/brunodelb
i.youku.com/brunodelb | www.weibo.com/brunodelb | blog.delb.cn
http://i.youku.com/brunoparis
Weibo
Siteofficiel
Lesson : Telephony, calls
2. Telephony, the calls
• In this lesson, you will learn to intercept incoming calls.
• For this, you will learn to use the telephony manager
TelephonyManager.
3. Telephony, the calls
• You have to use the telephony manager with getSystemService.
TelephonyManager telephonyManager =
(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
• Register a listener PhoneStateListener.
MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener();
telephonyManager.listen(myPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
4. Telephony, the calls
• Manage the events (ringing, hang up, …) in the method
onCallStateChanged().
public class MyPhoneStateListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch(state) {
case TelephonyManager.CALL_STATE_IDLE: break;
case TelephonyManager.CALL_STATE_RINGING: break;
case TelephonyManager.CALL_STATE_OFFHOOK: break;
}
}
}
5. Telephony, the calls
• When the application is interrupted (onPause() called), unregister the listening with
the event LISTEN_NONE.
public void onPause() {
telephonyManager.listen(myPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
• When the application is resumed (onResume() called), re-register the listening with
the event LISTEN_CALL_STATE.
public void onResume() {
telephonyManager.listen(myPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
12. Follow me on my channel PengYooTV …
On my Youku channel
http://i.youku.com/brunoparis
Who am I ?
Bruno Delb (www.delb.cn),
Author of the first french book of development of Java mobile application (2002),
Consultant, project manager and developer of social & mobile applications,
let’s talk about your needs ...
And on Weibo :
http://www.weibo.com/brunodelb