when i insert it into the headphone jack hole , the phone recognizes it as a headphone and the audio is directed to it , but , if i before install the "pressy" app , when i put the jack inside the hole, the system asks me if i want to use the phone as normal or if i want to send the audio to the headphone , and if i reply yes , the audio is sent to the internal speaker and mic , even thought the jack is inserted into the hole .
Sub SetEarPhone(Value As Boolean)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
Dim mode As Int
If Value Then mode = 2 Else mode = 0
r.RunMethod2("setMode", mode, "java.lang.int")
End Sub
but even with false or true , the audio coming from a call remain into the headphone and does0t go to the phone internal ear speaker .
You can try with a simple external headphone (earphone)
Dim jo As JavaObject
jo.InitializeContext
Dim r As Reflector
r.Target = jo.RunMethod("getSystemService", Array("audio"))
r.RunMethod4("setWiredDeviceConnectionState", Array (4, 0, "device"), _
Array As String("java.lang.int", "java.lang.int", "java.lang.String"))
java.lang.NoSuchMethodException: setWiredDeviceConnectionState [int, int, class java.lang.String]
at java.lang.Class.getMethod(Class.java:1981)
at java.lang.Class.getDeclaredMethod(Class.java:1960)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
at b4a.smart.home.main._button4_click(main.java:547)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6205)
at android.widget.TextView.performClick(TextView.java:11103)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
even the Jmu5667 example code has the same problem with android 7 :
Dim jo AsJavaObject
jo.InitializeContext
Dim r AsReflector
r.Target = jo.RunMethod("getSystemService", Array("audio"))
r.RunMethod4("setWiredDeviceConnectionState", Array (4, 0, "device"), _ArrayAsString("java.lang.int", "java.lang.int", "java.lang.String"))