Android: Incoming call listener without permission
I found solution without this permission.
First of all (when our sip call start) we need request audio focus with lisener
mAudioManager.requestAudioFocus(afChangeListener, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
The afChangeListener can tell us then someboby changed audio focus and then we can check current audio channel. If current mode is AudioManager.MODE_IN_CALL or AudioManager.MODE_RINGTONE then we know that gsm call started.
AudioManager.OnAudioFocusChangeListener afChangeListener =
new AudioManager.OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
// Permanent loss of audio focus
// Pause playback immediately
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
ScheduledExecutorService scheduler = App.getInstance().obtainScheduler();
scheduler.schedule(() -> {
Logging.i(TAG, "onAudioFocusChange defer mode = " + mAudioManager.getMode());
switch (mAudioManager.getMode()) {
case AudioManager.MODE_RINGTONE:
case AudioManager.MODE_IN_CALL:
//**there we can start standby mode**
break;
}
}, 100, TimeUnit.MILLISECONDS);
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
Logging.i(TAG, "onAudioFocusChange AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK");
// Lower the volume, keep playing
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
// Your app has been granted audio focus again
//**there we can stop standby mode**
}
}
};