Issue
I have call receiver , after first incoming call , ringtone playing as usual , but after second or more incoming calls sound does not stop playing.
here call receiver :-
public class IncomingCallReceiver extends BroadcastReceiver {
/**
* Processes the incoming call, answers it, and hands it over to the
* WalkieTalkieActivity.
*
* @param context The context under which the receiver is running.
* @param intent The intent being received.
*/
WalkieTalkieActivity wtActivity;
public SipAudioCall.Listener listener;
public SipAudioCall incomingCall = null;
public static Ringtone r;
public int state = 0;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onReceive(Context context, Intent intent) {
wtActivity = (WalkieTalkieActivity) context;
try {
incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
if (incomingCall.getState() == 3) {
state = 1;
Log.e("BUTTON", "Incoming Call here" + wtActivity.manager);
wtActivity.updateStatus("INCOMING CALL " + incomingCall.getState());
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
r = RingtoneManager.getRingtone(context, uri);
audioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolume / 2, AudioManager.FLAG_PLAY_SOUND);
r.play();
wtActivity.setContentView(R.layout.incomig_call);
Log.e("peer profile", incomingCall.getPeerProfile().toString());
}
} catch (Exception e) {
if (incomingCall != null) {
incomingCall.close();
}
}
}
}
I have static r , to stop r.play , on when call is end , but after calling again , I can hear two ringtones , and when I do end call , one ringtone stop play, but second continuous playing I do not understand why please help me
Solution
If anyone will have same issue . you need just unregister receiver after end call or on reject . this.unregisterReceiver(yourReceiver);
Answered By - some freelancer