Android Question setSpeakerphoneOn- Android 9

Jmu5667

Well-Known Member
Licensed User
Hi

Has anyone got this working ? I have tried all existing methods, but none seem to work on 9.

This is the code being executed in an Activity
B4X:
Dim rr As Reflector
rr.Target = rr.GetContext
rr.Target = rr.RunMethod2("getSystemService", "audio", "java.lang.String")
rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean")

Unfiltered logs reports an error
B4X:
n setSpeakerphoneOn(), on: true, calling application: com.is.vitllinkSOS
setSpeakerphoneOn true java.lang.Throwable
   at android.media.AudioManager.setSpeakerphoneOn(AudioManager.java:1358)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
   at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:817)
   at com.is.vitllinkSOS.main._tmrclock_tick(main.java:8581)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
   at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
   at android.os.Handler.handleCallback(Handler.java:873)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:193)
   at android.app.ActivityThread.main(ActivityThread.java:6863)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
com.is.vitllinkSOSdo not have using speaker authority in call

Regards

John.
 
Last edited:

emexes

Well-Known Member
Licensed User
I don't know, but a wildly uniformed throw-of-the-dart is: could it have something to do with permissions, alongside the PlayStore clampdown on accessing the Phone services?

This line from the log hints in that direction:
B4X:
com.is.vitllinkSOSdo not have using speaker authority in call
 

Jmu5667

Well-Known Member
Licensed User
Thanks for all the help on this one, is it possible that specific Devices can outright refuse MODIFY_PHONE_STATE permission ?

B4X:
07/15/2019 10:43:01.818 - Atlas SOS - main(), alert_make_call, Attempting call 1 of 1 to +35319012079 <- My app logging, rest is unfiltered log
In isSpeakerphoneOn(), calling application: com.is.vitllinkSOS
In isSpeakerphoneOn(), mForcedUseForCommExt: 0
PPD setMode mode = 2
Elem: dalvik.system.VMStack.getThreadStackTrace(Native Method)
Elem: java.lang.Thread.getStackTrace(Thread.java:1538)
Elem: android.media.AudioManager.setMode(AudioManager.java:1831)
Elem: java.lang.reflect.Method.invoke(Native Method)
Elem: anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
Elem: com.is.vitllinkSOS.cls_audio._vvvvvvvvvvvvvvvvvvvvv0(cls_audio.java:177)
Elem: com.is.vitllinkSOS.svc_service$ResumableSub_alert_make_call.resume(svc_service.java:325)
Elem: com.is.vitllinkSOS.svc_service._alert_make_call(svc_service.java:194)
Elem: com.is.vitllinkSOS.svc_service._process_alert_activation(svc_service.java:2546)
Elem: com.is.vitllinkSOS.svc_service._tmrservicehelper_tick(svc_service.java:2921)
Elem: java.lang.reflect.Method.invoke(Native Method)
Elem: anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
Elem: anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
Elem: android.os.Handler.handleCallback(Handler.java:873)
Elem: android.os.Handler.dispatchMessage(Handler.java:99)
Elem: android.os.Looper.loop(Looper.java:193)
Elem: android.app.ActivityThread.main(ActivityThread.java:6863)
Elem: java.lang.reflect.Method.invoke(Native Method)
Elem: com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
Elem: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
setMode(mode = 2, callingPackage = com.is.vitllinkSOS, Process ID: 22591
MODIFY_PHONE_STATE Permission Denial: setMode(MODE_IN_CALL) from pid=22591, uid=10105
In setSpeakerphoneOn(), on: true, calling application: com.is.vitllinkSOS
setSpeakerphoneOn true java.lang.Throwable
   at android.media.AudioManager.setSpeakerphoneOn(AudioManager.java:1358)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
   at com.is.vitllinkSOS.cls_audio._vvvvvvvvvvvvvvvvvvvvv0(cls_audio.java:183)
   at com.is.vitllinkSOS.svc_service$ResumableSub_alert_make_call.resume(svc_service.java:325)
   at com.is.vitllinkSOS.svc_service._alert_make_call(svc_service.java:194)
   at com.is.vitllinkSOS.svc_service._process_alert_activation(svc_service.java:2546)
   at com.is.vitllinkSOS.svc_service._tmrservicehelper_tick(svc_service.java:2921)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
   at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
   at android.os.Handler.handleCallback(Handler.java:873)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:193)
   at android.app.ActivityThread.main(ActivityThread.java:6863)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
isHasSpeakerAuthority APP keys: com.is.vitllinkSOS,mIsTelName=false
isInCallState =false
In setSpeakerphoneOn(), on: true, eventSource: setSpeakerphoneOn(true) from u/pid:10105/22591
In setSpeakerphoneOn(), mForcedUseForCommExt: 1
PPD setMode mode = 0
Elem: dalvik.system.VMStack.getThreadStackTrace(Native Method)
Elem: java.lang.Thread.getStackTrace(Thread.java:1538)
Elem: android.media.AudioManager.setMode(AudioManager.java:1831)
setForceUse() usage 0, config 1, mPhoneState 0
Elem: java.lang.reflect.Method.invoke(Native Method)
Elem: anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
checkOutputForAllStrategies()
The above is from unfiltered logs on a OnePlus 3 (A3003).

Regards

John.
 

OliverA

Expert
Licensed User

Jmu5667

Well-Known Member
Licensed User
I have the same trouble..
Exists some soultion, please Friends?
p4ppc
I would suggest that you look at the unfiltered logs on the device that it does not work on, see post #7. I have the same code working fine on other devices that have android 9 on them so it seem to be a device specific issue, which is beyond your control.
 
Top