mTelephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mPhoneStateListener = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
Log.e(JamendoApplication.TAG, "onCallStateChanged");
if (state == TelephonyManager.CALL_STATE_IDLE)//没有任何电话时 状态为IDLE
{
// resume playback
} else {
if(mPlayerEngine != null){
mPlayerEngine.pause();
}
}
}
};
mPhoneStateListener = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
Log.e(JamendoApplication.TAG, "onCallStateChanged");
if (state == TelephonyManager.CALL_STATE_IDLE)//没有任何电话时 状态为IDLE
{
// resume playback
} else {
if(mPlayerEngine != null){
mPlayerEngine.pause();
}
}
}
};
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);//开启监听
@Override
public void onDestroy() {
// TODO Auto-generated method stub
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);//注销监听
super.onDestroy();
}
当你没有任何电话是,状态是 IDLE ,当接到电话时是 OFFHOOK ,电话结束后返回 IDLE 状态。