0

I need to create a service which runs in the background and detects if the phone loud-speaker is being used. I need to listen for a phone "loud-speaker event" (ON or OFF) and perform an action depends on the state of the loud speaker.

yarian
  • 5,922
  • 3
  • 34
  • 48
Rami
  • 39
  • 1
  • 6
  • you means Headphones plugged or not ?? (headphones pluged means speak is off vice versa headphones unplugged means speaker is on .) – itsrajesh4uguys Feb 26 '13 at 08:45
  • I need my service to know every time the Speaker (not ringer) is used. Lets say a conversation is going on and the user put the Phone Speaker ON, I need my service to react to it. – Rami Feb 26 '13 at 09:03
  • you can.. i need to know what do you mean by Speaker ?? mediavolume or headphones plugging or some other things ? i think you are mentioning about loudspeak on and off while user in call right ? – itsrajesh4uguys Feb 26 '13 at 09:08
  • Yes, I mean the loudspeaker while in call. – Rami Feb 26 '13 at 09:43

1 Answers1

0

You can register a BroadcastReceiver with the AudioManager.RINGER_MODE_CHANGED action, which will be fired when the sound profile changes. Inside the onReceiver() you can call AudioManager's getRingerMode() method, which will return RINGER_MODE_NORMAL, RINGER_MODE_SILENT or RINGER_MODE_VIBRATE. Hope this helps.

Egor
  • 39,695
  • 10
  • 113
  • 130
  • would the AudioManager.RINGER_MODE_CHANGED be fired no matter which application is using the speaker? – Rami Feb 26 '13 at 08:57
  • dear Egor, I think I was misunderstood.. I need my service to know every time the Speaker (not ringer) is used. Lets say a conversation is going on and the user puts the Phone Speaker ON, I need my service to react to it.(and to OFF state as well) – Rami Feb 26 '13 at 09:02
  • @Rami, Then you would probably want to edit your question to make it more clear for the others. – Egor Feb 26 '13 at 09:14
  • I certainly agree with you, nevertheless do you have an answer to my question please? – Rami Feb 26 '13 at 09:22