如何监听Phone的状态,第三方App如何拨打/接听电话?
2014-12-01 17:32
423 查看
Android Version]
Android V2.3 (GB, GB2,GB3)
Android V4.0, V4.1 (ICS, ICS2, JB)
Android V4.2 (JB2,JB3,JB5)
[DESCRIPTION]
Android提供了类PhoneStateListener以方便非Phone进程时监听Phone的状态,如Phone State,Service State,Signal Strength,Call forward,VoiceMail Indicator,Cell Location等。
Android提供了Interface ITelephony来帮助第三方App实现拨打、接听、挂断电话等操作。
类PhoneStateListener的实现在文件:PhoneStateListener.java (frameworks\base\telephony\java\android\telephony)中
类ITelephony的实现在文件:PhoneInterfaceManager.java (packages\apps\Phone\src\com\android\phone)中
[SOLUTION]
监听Phone状态:
1、 import android.telephony.PhoneStateListener.
2、 实现一个继承自PhoneStateListener的类(内部类、匿名类、普通类均可),并实例化该类。
例如 PhoneStateListener myListener = new PhoneStateListener(){...};
对于需要监听的状态,重写相应的函数。例如:希望监听Phone的状态,则重写public void onCallStateChanged(int state, String inComingNumber);
其中各参数的含义请参考PhoneStateListener的注释。
3、 书写代码
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(myListener, PhoneStateListener.LISTEN_CALL_STATE);//单卡
或 tm.listenGemini(myListener, PhoneStateListener.LISTEN_CALL_STATE, Phone.GEMINI_SIM_1);//双卡
第三方App控制电话行为
ITelephony phone = (ITelephony)ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
拨打电话:phone.call (单卡), phone.callGemini
(双卡),其他的行为可参考PhoneInterfaceManager中的函数。
最后请注意:
PhoneStateListener需要在使用完后调用TelephonyManager.listen(myListener, PhoneStateListener.LISTEN_NONE)来释放引用,否则会引起OOM问题。
Android V2.3 (GB, GB2,GB3)
Android V4.0, V4.1 (ICS, ICS2, JB)
Android V4.2 (JB2,JB3,JB5)
[DESCRIPTION]
Android提供了类PhoneStateListener以方便非Phone进程时监听Phone的状态,如Phone State,Service State,Signal Strength,Call forward,VoiceMail Indicator,Cell Location等。
Android提供了Interface ITelephony来帮助第三方App实现拨打、接听、挂断电话等操作。
类PhoneStateListener的实现在文件:PhoneStateListener.java (frameworks\base\telephony\java\android\telephony)中
类ITelephony的实现在文件:PhoneInterfaceManager.java (packages\apps\Phone\src\com\android\phone)中
[SOLUTION]
监听Phone状态:
1、 import android.telephony.PhoneStateListener.
2、 实现一个继承自PhoneStateListener的类(内部类、匿名类、普通类均可),并实例化该类。
例如 PhoneStateListener myListener = new PhoneStateListener(){...};
对于需要监听的状态,重写相应的函数。例如:希望监听Phone的状态,则重写public void onCallStateChanged(int state, String inComingNumber);
其中各参数的含义请参考PhoneStateListener的注释。
3、 书写代码
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(myListener, PhoneStateListener.LISTEN_CALL_STATE);//单卡
或 tm.listenGemini(myListener, PhoneStateListener.LISTEN_CALL_STATE, Phone.GEMINI_SIM_1);//双卡
第三方App控制电话行为
ITelephony phone = (ITelephony)ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
拨打电话:phone.call (单卡), phone.callGemini
(双卡),其他的行为可参考PhoneInterfaceManager中的函数。
最后请注意:
PhoneStateListener需要在使用完后调用TelephonyManager.listen(myListener, PhoneStateListener.LISTEN_NONE)来释放引用,否则会引起OOM问题。
相关文章推荐
- android关于监听电话拨打后,对方接听的状态(COLP被连接线识别提示)
- 监听手机拨打电话的状态 private PhoneStateListener getPhoneStateListener()
- android之通过phoneStateListener监听电话状态改变
- android监听用户的拨打电话的状态
- android 2.1 监听电话状态并自动接听来电
- android 2.1 监听电话状态并自动接听来电
- android 电话状态的监听(来电和去电) PhoneStateListener和TelephonyManager
- MTK Android拨打电话如何获取适时状态
- Call.State 拨打电话状态监听
- Android 如何判断拨打电话对方是否接听
- Android监听手机电话状态与发送邮件通知来电号码的方法(基于PhoneStateListene实现)
- Nice link to figure out country code and phone format to call cross countries - 一个关于如何拨打跨国电话的好网站
- android 电话状态的监听(来电和去电) PhoneStateListener和TelephonyManager
- 如何监听电话状态
- android之通过phoneStateListener监听电话状态改变
- android 2.1 监听电话状态并自动接听来电
- android 2.1 监听电话状态并自动接听来电
- android 2.1 监听电话状态并自动接听来电
- 使用jqMobi开发app基础:如何拨打电话?
- Android 监听电话的拨打状态