I implemented an app which has a button speaker, which is manually set "on" by myAudioManager.setSpeakerphoneOn(true) and "off" vice-versa. But the bug is when you close the application while the speaker is on, it forgets the speaker was on. The next time, the speaker remains on and the call is by default in speaker mode. I don't want to set speaker off when app is in background, only when the app gets killed it has to be set off. onDestroy() works good, but it wont gets called all the time according to the lifecycle.
How to set speaker phone off when the app is killed by the "Recent App drawer"
170 views Asked by lijo050 At
2
Use a service like:
Add service to Manifest:
And start the service in your activity's
onCreate()
method with:Hope this helps you out.