4

i need to find whether speaker phone is on or not through programmability.

I know that we can find using below method whether it is on or not.

AudioManager.isSpeakerphoneOn();

in my case even it is returning false, even though the speaker is on by some how.

I need to know below 2 things.

1.is there any broadcast action to find speaker state.

2.is there any way to find speaker phone state change

user388269
  • 363
  • 2
  • 5
  • 10
  • How are you getting you AudioManager. I hope you are getting from your application context. (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); If yes, then it should work. (its a system wide service and you are not asked to meddle with it unless your application is handling telephony et a) – uncaught_exceptions Jan 19 '11 at 04:41
  • yes, actually the case is once the voice call is connected i am starting my application. in this case speaker is switching on. is there any thing relating with telephony now. can u please suggest – user388269 Jan 19 '11 at 06:13
  • I think you should use the broadcast receiver, as displayed here: [ Ringer mode change listener Broadcast receiver][1] [1]: http://stackoverflow.com/questions/7483961/ringer-mode-change-listener-broadcast-receiver – Lavekush Agrawal Apr 16 '14 at 04:22

3 Answers3

0

Try this for speaker ON functionality.

AudioManager audioManager = (AudioManager) Home.this.getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(true);
audioManager.setMode(AudioManager.MODE_IN_CALL);
0

Check the below link. Might be useful.

Turn on speakerphone whenever an outgoing call is made

But the link does not use broadcast reciever. It only checks if the speaker feature is on or not at that instant.

Community
  • 1
  • 1
ngrashia
  • 9,869
  • 5
  • 43
  • 58
0

Here you Go

AudioManager audioManager = (AudioManager) MainActivity.this .getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_IN_CALL);

    if(audioManager.isSpeakerphoneOn()){
        audioManager.setSpeakerphoneOn(true);


    }else if(!audioManager.isSpeakerphoneOn()){


    }
Umer Kiani
  • 3,783
  • 5
  • 36
  • 63