My application makes a phone automatically answer incoming calls for a predefined length of time. However, I can't manage to trigger the speakerphone, which would also activate automatically when these incoming calls are received. Does this feature exist on Android 12 or higher?
public void answerIncomingCall(Context context) throws InterruptedException { TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);
if (telecomManager != null && telecomManager.isInCall()) {
//wait(1000);
// Check if the AudioManager is available
// Vérifier si AudioManager est disponible
if (audioManager != null) {
if(!audioManager.isSpeakerphoneOn()) {
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
}
Log.e("setSpeakerphoneOn","is:"+audioManager.isSpeakerphoneOn());
}
telecomManager.acceptRingingCall();
}
}
Unfortunately, the speaker doesn't activate when a call is received.