Android PhoneStateListener

PhoneStateListener

 我们可以通过    

TelephoneManager  服务来 监听 电话的状态

 

1:   private  TelephonyManager tm;

                 tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

 2: 写一个类继承  PhoneStateListener

 

3:重写 @Override

  public void onCallStateChanged(int state, String incomingNumber) {
   // TODO Auto-generated method stub
   super.onCallStateChanged(state, incomingNumber);
  }

方法

4:电话状态

TelephonyManager.CALL_STATE_IDLE:              手机空闲起来了  

TelephonyManager.CALL_STATE_RINGING:   手机铃声响了,

    来电号码incomingNumber;              

 TelephonyManager.CALL_STATE_OFFHOOK:   电话被挂起了 

注册事件

5: tm.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

6:取消事件

  tm.listen(listener, PhoneStateListener.LISTEN_NONE);
     listener = null;

 

[java]
 public void onServiceStateChanged(ServiceState serviceState)
 public void onMessageWaitingIndicatorChanged(boolean mwi) 
 public void onCallForwardingIndicatorChanged(boolean cfi)
 public void onCellLocationChanged(CellLocation location) 
 public void onCallStateChanged(int state, String incomingNumber) 
 public void onDataConnectionStateChanged(int state) 
 public void onDataConnectionStateChanged(int state, int networkType) 
 public void onDataActivity(int direction) 
 public void onSignalStrengthsChanged(SignalStrength signalStrength) 
 public void onServiceStateChanged(ServiceState serviceState)
 public void onMessageWaitingIndicatorChanged(boolean mwi)
 public void onCallForwardingIndicatorChanged(boolean cfi)
 public void onCellLocationChanged(CellLocation location)
 public void onCallStateChanged(int state, String incomingNumber)
 public void onDataConnectionStateChanged(int state)
 public void onDataConnectionStateChanged(int state, int networkType)
 public void onDataActivity(int direction)
 public void onSignalStrengthsChanged(SignalStrength signalStrength)
 2)int events
 
Events取值如下:
 
[java]
 public static final int LISTEN_NONE = 0; //停止监听 
 public static final int LISTEN_SERVICE_STATE = 0x00000001;
 public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 0x00000004;
 public static final int LISTEN_CALL_FORWARDING_INDICATOR = 0x00000008;
 public static final int LISTEN_CELL_LOCATION = 0x00000010;
 public static final int LISTEN_CALL_STATE = 0x00000020;
 public static final int LISTEN_DATA_CONNECTION_STATE = 0x00000040;
 public static final int LISTEN_DATA_ACTIVITY = 0x00000080;
 public static final int LISTEN_SIGNAL_STRENGTHS = 0x00000100;
 public static final int LISTEN_NONE = 0; //停止监听
 public static final int LISTEN_SERVICE_STATE = 0x00000001;
 public static final int LISTEN_MESSAGE_WAITING_INDICATOR = 0x00000004;
 public static final int LISTEN_CALL_FORWARDING_INDICATOR = 0x00000008;
 public static final int LISTEN_CELL_LOCATION = 0x00000010;
 public static final int LISTEN_CALL_STATE = 0x00000020;
 public static final int LISTEN_DATA_CONNECTION_STATE = 0x00000040;
 public static final int LISTEN_DATA_ACTIVITY = 0x00000080;
 public static final int LISTEN_SIGNAL_STRENGTHS = 0x00000100;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值