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
Try this for speaker ON functionality.
AudioManager audioManager = (AudioManager) Home.this.getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(true);
audioManager.setMode(AudioManager.MODE_IN_CALL);
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.
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()){
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.