android-PhoneStateListener
来源:互联网 发布:一个程序员的基本技术 编辑:程序博客网 时间:2024/06/08 00:47
honeStateListener
1.对特定的电话状态的监听,包括服务的状态、信号强度、消息等待指示(语音信箱)、通话转移、呼叫状态、设备单元位置、数据连接状态、数据流量方向。一些电话信息受权限保护,应用程序不会收到受保护的信息的更新,除非在manifest文件中有适当的权限声明。凡申请许可,有适当的LISTEN_标志。
2.对监听的话做处理
Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case LISTEN_SERVICE_STATE:/*Listen for changes to the network service state (cellular).对网络服务状态监听*/ PhoneStateListener.this.onServiceStateChanged((ServiceState)msg.obj); break; case LISTEN_SIGNAL_STRENGTH:/*Listen for changes to the network signal strength (cellular).对网络信号强度变化监听*/ PhoneStateListener.this.onSignalStrengthChanged(msg.arg1); break; case LISTEN_MESSAGE_WAITING_INDICATOR:/*Listen for changes to the message-waiting indicator.对消息等待指示的变化监听*/ PhoneStateListener.this.onMessageWaitingIndicatorChanged(msg.arg1 != 0); break; case LISTEN_CALL_FORWARDING_INDICATOR:/*Listen for changes to the call-forwarding indicator.对通话转移指示的变化监听*/ PhoneStateListener.this.onCallForwardingIndicatorChanged(msg.arg1 != 0); break; case LISTEN_CELL_LOCATION:/*Listen for changes to the device's cell location. Note that this will result in frequent callbacks to the listener.对设备单元位置的变化监听,这会导致频繁的监听回调。*/ PhoneStateListener.this.onCellLocationChanged((CellLocation)msg.obj); break; case LISTEN_CALL_STATE:/*Listen for changes to the device call state.对设备呼叫状态的变化监听。*/ PhoneStateListener.this.onCallStateChanged(msg.arg1, (String)msg.obj); break; case LISTEN_DATA_CONNECTION_STATE:/*Listen for changes to the data connection state (cellular).对数据连接状态的变化监听。*/ PhoneStateListener.this.onDataConnectionStateChanged(msg.arg1, msg.arg2); PhoneStateListener.this.onDataConnectionStateChanged(msg.arg1); break; case LISTEN_DATA_ACTIVITY:/*Listen for changes to the direction of data traffic on the data connection (cellular).对数据流量移动方向的变化监听*/ PhoneStateListener.this.onDataActivity(msg.arg1); break; case LISTEN_SIGNAL_STRENGTHS:/*Listen for changes to the network signal strengths (cellular).对网络信号强度的变化监听*/ PhoneStateListener.this.onSignalStrengthsChanged((SignalStrength)msg.obj); break; } }};
3.监听变化后发送消息
IPhoneStateListener callback = new IPhoneStateListener.Stub() { public void onServiceStateChanged(ServiceState serviceState) { Message.obtain(mHandler, LISTEN_SERVICE_STATE, 0, 0, serviceState).sendToTarget(); } public void onSignalStrengthChanged(int asu) { Message.obtain(mHandler, LISTEN_SIGNAL_STRENGTH, asu, 0, null).sendToTarget(); } public void onMessageWaitingIndicatorChanged(boolean mwi) { Message.obtain(mHandler, LISTEN_MESSAGE_WAITING_INDICATOR, mwi ? 1 : 0, 0, null) .sendToTarget(); } public void onCallForwardingIndicatorChanged(boolean cfi) { Message.obtain(mHandler, LISTEN_CALL_FORWARDING_INDICATOR, cfi ? 1 : 0, 0, null) .sendToTarget(); } public void onCellLocationChanged(Bundle bundle) { CellLocation location = CellLocation.newFromBundle(bundle); Message.obtain(mHandler, LISTEN_CELL_LOCATION, 0, 0, location).sendToTarget(); } public void onCallStateChanged(int state, String incomingNumber) { Message.obtain(mHandler, LISTEN_CALL_STATE, state, 0, incomingNumber).sendToTarget(); } public void onDataConnectionStateChanged(int state, int networkType) { Message.obtain(mHandler, LISTEN_DATA_CONNECTION_STATE, state, networkType, null). sendToTarget(); } public void onDataActivity(int direction) { Message.obtain(mHandler, LISTEN_DATA_ACTIVITY, direction, 0, null).sendToTarget(); } public void onSignalStrengthsChanged(SignalStrength signalStrength) { Message.obtain(mHandler, LISTEN_SIGNAL_STRENGTHS, 0, 0, signalStrength).sendToTarget(); }};
- android-PhoneStateListener
- Android PhoneStateListener
- PhoneStateListener
- PhoneStateListener
- Android 利用PhoneStatelistener 判断网络是否连接
- 通过PhoneStateListener实现Android电话监听
- Android应用开发之PhoneStateListener 的使用
- developer.Android.com:PhoneStateListener :onServiceStateChanged(ServiceState serviceState)
- android PhoneStateListener 内存泄露的问题
- android之通过phoneStateListener监听电话状态改变
- android之通过phoneStateListener监听电话状态改变
- android之通过phoneStateListener监听电话状态改变
- android之通过phoneStateListener监听电话状态改变
- android 电话状态的监听(来电和去电) PhoneStateListener和TelephonyManager
- 举例说明如何在android中实现设置黑名单的功能--AudioManager、PhoneStateListener的使用
- android 电话状态的监听(来电和去电) PhoneStateListener和TelephonyManager
- android 电话状态的监听(来电和去电) PhoneStateListener和TelephonyManager
- Android获取手机信息--TelephonyManager类和PhoneStateListener类详解及其使用
- DataGrid全选功能(使用MVVM架构)
- Android的图片压缩类ThumbnailUtils(有源码)
- c3p0 connection too many
- 分享我的位置与分享POI的异同
- 关于设置JFrame大小
- android-PhoneStateListener
- iOS开发 SDK兼容性
- 不让EditTextView获取焦点
- 解决“无法删除 指定的文件名无效或太长”的问题
- 十大优秀jQuery插件推荐
- 如何在linux中虚拟网卡
- TCP/IP,HTTP,SOAP等协议之区别
- ssl中间人攻击
- windows下Emacs的安装与配置