I have an android app that plays audio from the application class. I have a PhoneStateListener in my application class that pauses the audio when there is a phone call.
I want to start a particular activity when the call ends, but I am unable to. here is my code:
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
.....
.....
}
I would appreciate it if someone could show me how to start the activity in the correct manner.
Thanks!
Ok so I know you found another solution already, but I was cracking around at it and found something that worked for me. Instead of calling an intent I used pendingIntent, an intent filter, and pending post. Here is a code snippit for anyone else out there having this issue.
Then in your manifest just make sure you set the intent filter for the catching activity