0
有一項服務,處理的媒體播放器希望爲接收和撥出的呼叫服務停止的媒體播放器執行此操作,並在呼叫流程結束時繼續播放。 現在只設法停止傳入和傳出呼叫的回放,應該添加代碼來播放TelephonyManager.CALL_STATE_IDLE:然後在音樂開始一段時間後通話,如何解決它?BroadcastReceiver中的撥入和撥出電話
public class CallReceiver extends BroadcastReceiver{
TelephonyManager telManager;
Context context;
boolean startedCall = false;
@Override
public void onReceive(Context context, Intent intent) {
this.context=context;
telManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}
private final PhoneStateListener phoneListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
try {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING: {
if(incomingNumber!=null)
{
//incoming call
MediaService.stopMP();
startedCall = true;
}
break;
}
case TelephonyManager.CALL_STATE_OFFHOOK: {
if(incomingNumber!=null)
{
//outgoing call
MediaService.stopMP();
startedCall = true;
}
break;
}
case TelephonyManager.CALL_STATE_IDLE: {
if(startedCall)
{
MainActivity.titleMusic.setVisibility(View.VISIBLE);
MainActivity.Play();
MediaService.startMP();
startedCall = false;
}
break;
}
default: { }
}
} catch (Exception ex) {
}
}
};
}
傳出呼叫似乎不打開,並且當傳入也在對話的背景上播放時,呼叫再次從中斷緩衝區開始。更正了有問題的代碼 – user3064772
它可以是有幫助的:http://stackoverflow.com/questions/13377852/handling-incoming-calls-in-android-application – YasirSE