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

 
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…