hookshy Well-Known Member Licensed User Longtime User Mar 6, 2016 #1 Can you turn the loudspeaker on this adroid version ? For previous versions the code below works perfect : I use it together with phone events to rise the following code . B4X: Dim rr As Reflector rr.Target = rr.GetContext rr.Target = rr.RunMethod2("getSystemService", "audio", "java.lang.String") rr.RunMethod2("setMode", "2", "java.lang.int") rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean") Thank you .
Can you turn the loudspeaker on this adroid version ? For previous versions the code below works perfect : I use it together with phone events to rise the following code . B4X: Dim rr As Reflector rr.Target = rr.GetContext rr.Target = rr.RunMethod2("getSystemService", "audio", "java.lang.String") rr.RunMethod2("setMode", "2", "java.lang.int") rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean") Thank you .
somed3v3loper Well-Known Member Licensed User Longtime User Mar 6, 2016 #2 This worked for me on lollipop http://stackoverflow.com/questions/...ough-the-speakers-when-headphones-are-plugged B4X: Dim java As JavaObject java.InitializeContext java.RunMethod("setSpeakerOn",Null) B4X: #If JAVA import android.media.AudioManager; public void setSpeakerOn() { AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); audioManager.setSpeakerphoneOn(true); } #End if And add the permission in manifest B4X: AddPermission("android.permission.MODIFY_AUDIO_SETTINGS") Upvote 0
This worked for me on lollipop http://stackoverflow.com/questions/...ough-the-speakers-when-headphones-are-plugged B4X: Dim java As JavaObject java.InitializeContext java.RunMethod("setSpeakerOn",Null) B4X: #If JAVA import android.media.AudioManager; public void setSpeakerOn() { AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); audioManager.setSpeakerphoneOn(true); } #End if And add the permission in manifest B4X: AddPermission("android.permission.MODIFY_AUDIO_SETTINGS")
hookshy Well-Known Member Licensed User Longtime User Mar 7, 2016 #3 Thanks , it helps me a lot. Upvote 0
NeoTechni Well-Known Member Licensed User Longtime User Jun 26, 2016 #4 I'm getting an error using that code B4X: #If JAVA import android.media.AudioManager; public void setSpeakerOn(boolean Value) { AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); audioManager.setSpeakerphoneOn(Value); } #End if I changed it to take the value as a parameter It says: error: cannot find symbol symbol: variable AUDIO_SERVICE Upvote 0
I'm getting an error using that code B4X: #If JAVA import android.media.AudioManager; public void setSpeakerOn(boolean Value) { AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); audioManager.setSpeakerphoneOn(Value); } #End if I changed it to take the value as a parameter It says: error: cannot find symbol symbol: variable AUDIO_SERVICE
NeoTechni Well-Known Member Licensed User Longtime User Jun 26, 2016 #5 I got it "working" by moving the code to the activity instead of the service However it still doesn't actually activate the speakerphone on Android 5 Upvote 0
I got it "working" by moving the code to the activity instead of the service However it still doesn't actually activate the speakerphone on Android 5
NeoTechni Well-Known Member Licensed User Longtime User Jun 26, 2016 #6 They changed it to MODE_IN_COMMUNICATION... Upvote 0