I am developing a Phone application I want to turn speaker ON/OFF in call. I want to enable and disable the speaker with a button click and I am using the following code. I tried different methods to turn on speakerphone but those are not worked.
AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);