Android Question Beep sound by the external speaker

Glitchs

Member
Licensed User
Longtime User
Hello.

My app alerts of a near GPS point with a Beep sound. It works ok but when the phone is connected to the hands free Bluetooth of the car the sound is send by BT to the audio system of the car. If for example I am not listening the BT sound of the car and I am listening the FM radio, I cant listen any alert because this alert is sent to the car. How can I force the phone to sound the beep alert o for example the TTS speech sound alert to the external speaker as other apps like Waze, even connected to the hands free bluetooth. I have read some but is for calls objets and this is not a call phone.

Thanks very much.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Sub ForceSpeaker
   Dim jo As JavaObject
   jo.InitializeContext
   Dim audioManager As JavaObject = jo.RunMethod("getSystemService", Array("audio"))
   audioManager.RunMethod("setMode", Array(2)) 'MODE_IN_CALL
   audioManager.RunMethod("setSpeakerphoneOn", Array(True))
End Sub
Add this line to the manifest editor:
B4X:
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)

It is based on this answer: http://stackoverflow.com/questions/...ough-the-speakers-when-headphones-are-plugged
 
Upvote 0

Glitchs

Member
Licensed User
Longtime User
Ok, Thank you very much, a fast clear answer. What we'll do when you wil not be here? :)
Now I implement it at app and this evening I'll test it.
Thanks a lot.
 
Upvote 0

Glitchs

Member
Licensed User
Longtime User
Hello.

I have implemented the subroutine and it works. I just write de sub forcespeaker and I called it in the Activity_create.
Now the question is how I desactivate this mode?
I dont understand but the sub for desactivate will be this? With "False" paremeter?

B4X:
Sub ForceSpeaker
Dim jo AsJavaObject
jo.InitializeContext
Dim audioManager AsJavaObject = jo.RunMethod("getSystemService", Array("audio"))
audioManager.RunMethod("setMode", Array(2)) 'MODE_IN_CALL audioManager.RunMethod("setSpeakerphoneOn", Array(False))
End Sub

or I must to create a new SUB with "False" parameter like?

B4X:
Sub DisactivateForceSpeaker
Dim jo AsJavaObject
jo.InitializeContext
Dim audioManager AsJavaObject = jo.RunMethod("getSystemService", Array("audio"))
audioManager.RunMethod("setMode", Array(2)) 'MODE_IN_CALL 

audioManager.RunMethod("setSpeakerphoneOn", Array(False))
End Sub





I'd like to put a checkbox that alternate activating-desactivating this feature.


Thanks
 
Last edited:
Upvote 0
Top