android电话服务

来源:互联网 发布:淘宝京东三只松鼠 编辑:程序博客网 时间:2024/05/01 11:23

Android打电话也是两行代码: 
Intent intent = new Intent("android.intent.action.DIAL", Uri.parse("tel:10086") ); 
startActivity(intent); 
这样便进进入呼叫界面了。 

接下来我们再看一下监听电话状态的功能。 

监听电话状态首先建立一个继承于PhoneStateListener电话监听类(如:TeleListener),并让TelephonyManager监听它。 
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
mTelephonyMgr.listen(new TeleListener(), PhoneStateListener.LISTEN_CALL_STATE | PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTH); 
TeleListener需要实现父类的几个方法,onCallStateChanged、onServiceStateChanged、onSignalStrengthChanged,根据方法名我们便可知其功能,这里就不再详述。 

原创粉丝点击