我有一个播放音频的 Android 应用程序,它是从应用程序类播放的。我在应用程序类中有一个 PhoneStateListener,在电话呼叫时暂停音频。
当通话结束时,我想启动特定的活动,但我无法做到。以下是我的代码:
public void getPhoneState(){
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
if(audio.isPlaying())
audioPlayer.pause();
}
else if(state == TelephonyManager.CALL_STATE_IDLE) {
audio.start();
Intent missintent= new Intent(context,AudioActivity.class);
missintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(missintent);
}
else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
if(audio.isPlaying())
audioPlayer.pause();
}
super.onCallStateChanged(state, incomingNumber);
}
};
if(mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
public boolean handleAudio(String source, int id) {
phoneState();
//Code for Playing Audio
.....
.....
}
如果有人能向我展示如何正确地启动活动,我将不胜感激。
谢谢!