How to programmatically turn on the speaker when making / receiving a call?

Hey. I am new to android and still involved in the learning process. I am currently planning to make an application that will automatically turn on the speaker when the call is connected. Below are the codes.

audiomanager = (AudioManager) contex.getSystemService(Context.AUDIO_SERVICE);

  @Override
    public void onCallStateChanged(int state, String incomingNumber) {
               case TelephonyManager.CALL_STATE_OFFHOOK:
                           am.setSpeakerphoneOn(true); 
               break;
         }

I tested my code on Android android 2.1..sdk 7..i using audiomanager.setSpeakerphoneOn (true); and add the MODIFY_AUDIO_SETTINGS permission in the manifest, you can turn on the loudspeaker .. but it seems like it can't ... so can anyone help? thanks in advance.

+3
source share
1 answer

Make sure the spelling is contextcorrect

audiomanager = (AudioManager) contex***t***.getSystemService(Context.AUDIO_SERVICE);
0
source

Source: https://habr.com/ru/post/1778271/


All Articles