Android 开发之PhoneState与CallState
来源:互联网 发布:网络词背锅什么意思 编辑:程序博客网 时间:2024/06/06 10:41
Android 开发之PhoneState与CallState
最近在研究Phone应用,记录一下相关信息,希望对大家也会有用
实现手机电话状态的监听,主要依靠两个类:TelephoneManger和PhoneStateListener。
TelephonseManger提供了取得手机基本服务的信息的一种方式。因此应用程序可以使用TelephonyManager来探测手机基本服务的情况。
TelephonseManger提供了取得手机基本服务的信息的一种方式。因此应用程序可以使用TelephonyManager来探测手机基本服务的情况。
应用程序可以注册listener来监听电话状态的改变。我们不能对TelephonyManager进行实例化,只能通过获取服务的形式:
Context.getSystemService(Context.TELEPHONY_SERVICE);
Context.getSystemService(Context.TELEPHONY_SERVICE);
当然我们这里的重点不是服务
//電話狀態的Listener MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener(); //取得TelephonyManager TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); //將電話狀態的Listener加到取得TelephonyManager telephonyManager.listen(myPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } public class MyPhoneStateListener extends PhoneStateListener { @Override public void onCallStateChanged(int state, String phoneNumber) { switch (state) { //電話狀態是閒置的 case TelephonyManager.CALL_STATE_IDLE: break; //電話狀態是接起的 case TelephonyManager.CALL_STATE_OFFHOOK: Toast.makeText(MainActivity.this, "正接起電話…", Toast.LENGTH_LONG).show(); break; //電話狀態是響起的 case TelephonyManager.CALL_STATE_RINGING: Toast.makeText(MainActivity.this, phoneNumber + "正打電話來…", Toast.LENGTH_LONG).show(); break; default: break; } }
public void updatecallstate(Call call){final Call.State state = call.getState();switch (state) {case IDLE://通话空闲break;case ACTIVE://通话中break;case HOLDING://通话保持(等待回应(接听等))break;case DIALING:case ALERTING://拨号break;case INCOMING:case WAITING://来电break;case DISCONNECTING://正在挂断break;case DISCONNECTED://通话中断(网络等原因)break;}}
0 0
- Android 开发之PhoneState与CallState
- Android开发之旅:活动与任务
- Android开发之旅:进程与线程
- Android开发之旅:进程与线程
- Android开发之旅:进程与线程
- android开发之Activity与Service绑定
- Android开发之旅:活动与任务
- Android开发之旅:进程与线程
- Android开发之旅:活动与任务
- Android开发之旅:进程与线程
- Android开发笔记之《Activity与Intent》
- iOS与Android开发之比较
- Android开发之旅:活动与任务
- Android开发之旅:活动与任务
- Android开发学习之进程与线程
- Android开发之Bundle与Intent详解
- 【Android开发】之Fragment与Acitvity通信
- Android开发之反编译与防止反编译
- cocos2dx射箭等抛射物的简单解决方案
- Android 适配问题
- 2014-11-5
- Android-Dalvik指令集
- 49.穿越矩阵 (15分待续)
- Android 开发之PhoneState与CallState
- 类型转化LPCTSTR,std::string,VT_BSTR
- Ant Counting(3046)
- adb通过IP地址连接远端的模拟器
- Troubleshooting Common Networking Problems with Wireshark, Pt. 2: TCP Retransmissions
- Python xml属性/节点/文本的增删改[xml.etree.ElementTree]
- nil,Nil,NULL,NSNull的区别
- [LeetCode]Insert Interval 考虑多种情况
- 在Ubuntu上安装ADT的遭遇