start a phonecall in speaker mode

spezialmaterie

Member
Licensed User
Longtime User
hello,

i want to start a phonecall automatically in speaker mode but i cant find any options where i can do this...

is there a solution to do this?

regards
 

fabpalma

Member
Licensed User
Longtime User
Hi Erel,

I'm trying to place a phone call with the speaker on, but I get always a Java error.

I tried, as your suggestion:

r.RunMethod("setSpeakerphoneOn2", true, "java.lang.boolean")

but I think I need use RunMethode2 because there are more that one parameter.

So i tried:

B4X:
Dim pc As PhoneCalls 
StartActivity(pc.Call(number))
Dim rr As Reflector
rr.Target = rr.GetContext
rr.RunMethod2("setSpeakerphoneOn2", True, "java.lang.boolean")
but I still get a Java error

rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean")
java.lang.IllegalStateException: View com.android.internal.policy.impl.PhoneWindow$DecorView@2be2f3a8 has already been added to the window manager.

Is correct "setSpeakerphoneOn2" ?

Is correct to pass True to RunMethod2 when it expect 3 strings parameters ?

I have also added this string to the Manifest:
B4X:
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)

Many thanks in advance.
Fabrizio
 
Upvote 0

fabpalma

Member
Licensed User
Longtime User
Hi Erel,

yes, I googled and I found that the right name is "setSpeakerphoneOn" and I tried with it but the result is the same.
I tried also to change the "true" with "1" and the variable type to integer instead of boolean but without success.

This is the full error message from the log window.
I tried to call "190" and the phone call start, but then I get the error.

Uhmmm ... this code is inside a Service..... problem ???

Regards.
Fab

Cmd=CALL
Par=190

smsmanager_si_messagereceived (B4A line: 250)

rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean")
java.lang.IllegalStateException: View com.android.internal.policy.impl.PhoneWindow$DecorView@2be36988 has already been added to the window manager.


at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:244)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
at android.view.Window$LocalWindowManager.addView(Window.java:537)
at android.app.Dialog.show(Dialog.java:278)
at anywheresoftware.b4a.debug.Debug.wait(Debug.java:207)
at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:257)
at anywheresoftware.b4a.debug.Debug.ErrorCaught(Debug.java:146)
at com.infaser.mailsms.smsmanager._si_messagereceived(smsmanager.java:1040)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$1.onReceive(PhoneEvents.java:362)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x10 (has extras) } in anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$1@2bf10210


at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: View com.android.internal.policy.impl.PhoneWindow$DecorView@2be36988 has already been added to the window manager.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$1.onReceive(PhoneEvents.java:362)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
... 9 more
Caused by: java.lang.IllegalStateException: View com.android.internal.policy.impl.PhoneWindow$DecorView@2be36988 has already been added to the window manager.
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:244)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
at android.view.Window$LocalWindowManager.addView(Window.java:537)
at android.app.Dialog.show(Dialog.java:278)
at anywheresoftware.b4a.debug.Debug.wait(Debug.java:207)
at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:257)
at anywheresoftware.b4a.debug.Debug.ErrorCaught(Debug.java:146)
at com.infaser.mailsms.smsmanager._si_messagereceived(smsmanager.java:1040)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
... 12 more
problem removing interface quota


java.lang.IllegalStateException: Error communicating to native daemon
at com.android.server.NetworkManagementService.removeInterfaceQuota(NetworkManagementService.java:1161)
at com.android.server.net.NetworkPolicyManagerService.removeInterfaceQuota(NetworkPolicyManagerService.java:1517)
at com.android.server.net.NetworkPolicyManagerService.updateNetworkRulesLocked(NetworkPolicyManagerService.java:851)
at com.android.server.net.NetworkPolicyManagerService.access$1100(NetworkPolicyManagerService.java:148)
at com.android.server.net.NetworkPolicyManagerService$7.onReceive(NetworkPolicyManagerService.java:692)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: com.android.server.NativeDaemonConnectorException: Cmd {bandwidth removeiquota rmnet0} failed with code 400 : {Bandwidth command failed}


at com.android.server.NativeDaemonConnector.doCommandLocked(NativeDaemonConnector.java:281)
at com.android.server.NativeDaemonConnector.doCommand(NativeDaemonConnector.java:241)
at com.android.server.NetworkManagementService.removeInterfaceQuota(NetworkManagementService.java:1158)
... 9 more
problem setting interface quota


java.lang.IllegalStateException: Error communicating to native daemon
at com.android.server.NetworkManagementService.setInterfaceQuota(NetworkManagementService.java:1131)
at com.android.server.net.NetworkPolicyManagerService.setInterfaceQuota(NetworkPolicyManagerService.java:1507)
at com.android.server.net.NetworkPolicyManagerService.updateNetworkRulesLocked(NetworkPolicyManagerService.java:842)
at com.android.server.net.NetworkPolicyManagerService.access$1100(NetworkPolicyManagerService.java:148)
at com.android.server.net.NetworkPolicyManagerService$7.onReceive(NetworkPolicyManagerService.java:692)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: com.android.server.NativeDaemonConnectorException: Cmd {bandwidth setiquota rmnet0 783232955} failed with code 400 : {Bandwidth command failed}


at com.android.server.NativeDaemonConnector.doCommandLocked(NativeDaemonConnector.java:281)
at com.android.server.NativeDaemonConnector.doCommand(NativeDaemonConnector.java:241)
at com.android.server.NetworkManagementService.setInterfaceQuota(NetworkManagementService.java:1128)
... 9 more
 
Upvote 0

fabpalma

Member
Licensed User
Longtime User
Hi Erel,

ok, running in Release mode, the Java error change.
This is the full log relative to the error:

B4X:
java.lang.NoSuchMethodException: setSpeakerphoneOn [boolean]

   at java.lang.Class.getConstructorOrMethod(Class.java:460)
   at java.lang.Class.getDeclaredMethod(Class.java:685)
   at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:192)
   at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:795)
   at com.infaser.mailsms.smsmanager._filtercommandsms(smsmanager.java:210)
   at com.infaser.mailsms.smsmanager._messagemanager(smsmanager.java:525)
   at com.infaser.mailsms.smsmanager._si_messagereceived(smsmanager.java:671)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
   at anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$1.onReceive(PhoneEvents.java:362)
   at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
   at android.os.Handler.handleCallback(Handler.java:605)


   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4441)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x10 (has extras) } in anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$1@2beed6b8


   at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
   at android.os.Handler.handleCallback(Handler.java:605)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4441)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: setSpeakerphoneOn [boolean]
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
   at anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$1.onReceive(PhoneEvents.java:362)
   at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
   ... 9 more
Caused by: java.lang.NoSuchMethodException: setSpeakerphoneOn [boolean]
   at java.lang.Class.getConstructorOrMethod(Class.java:460)
   at java.lang.Class.getDeclaredMethod(Class.java:685)
   at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:192)
   at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:795)
   at com.infaser.mailsms.smsmanager._filtercommandsms(smsmanager.java:210)
   at com.infaser.mailsms.smsmanager._messagemanager(smsmanager.java:525)
   at com.infaser.mailsms.smsmanager._si_messagereceived(smsmanager.java:671)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   ... 12 more

java.lang.NoSuchMethodException: setSpeakerphoneOn [boolean] ??

I have checked the lower and upper case of the characters, and it seem to be correct...

What do you think ?
Thanks....
Fabrizio
 
Upvote 0

fabpalma

Member
Licensed User
Longtime User
Thanks, Erel !
Now it works !!

For everyone that need to start a phonecall with the speakerphone active:

B4X:
'start the call
Dim pc As PhoneCalls
StartActivity(pc.Call(cellNumber))

'open speakerphone                      
Dim rr As Reflector
rr.Target = rr.GetContext
rr.Target = rr.RunMethod2("getSystemService", "audio", "java.lang.String")        

rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean")

Thanks.
Fabrizio
 
Last edited by a moderator:
Upvote 0

ilan

Expert
Licensed User
Longtime User
this code doesnot work for me (Galaxy 2 Plus, Android 4.1.2)

it just makes a regular call without speaker on

added also to the manifest editor this line:

B4X:
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)

what am i doing wrong?
 
Upvote 0
Top