bluetooth serial.listeninsecure causing ioexception on some devices.

ghazuria

New Member
Licensed User
Longtime User
Hello all,

I am getting an exception while trying to initiate serial.listeninsecure. It works fine on my tablet but so far gives the error on my phone and on my android mini pc.

B4X:
Sub Service_Start (StartingIntent As Intent)
   tmrDiscovery.Initialize("tmrDiscovery",120000)
   tmrDiscovery.Enabled = True
   i.Initialize("android.bluetooth.adapter.action.REQUEST_DISCOVERABLE", "")
   i.PutExtra("android.bluetooth.adapter.extra.DISCOVERABLE_DURATION", 0)
   StartActivity(i)
   If b.StartDiscovery = False Then
      log("Error starting discovery for other devices")
   End If

   s.ListenInsecure(b,11) ' program causing exception here.....
   
End Sub

the errors are as follows:

partysharing_service_start (B4A line: 48)
s.ListenInsecure(b,11)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.objects.Serial.ListenInsecure(Serial.java:225)
at sytex.consulting.com.pictureparty.partysharing._service_start(partysharing.java:690)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
at sytex.consulting.com.pictureparty.partysharing.handleStart(partysharing.java:65)
at sytex.consulting.com.pictureparty.partysharing.onStartCommand(partysharing.java:50)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2490)
at android.app.ActivityThread.access$1900(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.IOException: Address already in use
at android.bluetooth.BluetoothSocket.throwErrnoNative(Native Method)
at android.bluetooth.BluetoothAdapter.listenUsingInsecureRfcommOn(BluetoothAdapter.java:1079)
... 21 more
java.lang.RuntimeException: Unable to start service sytex.consulting.com.pictureparty.partysharing@412d3538 with Intent { cmp=sytex.consulting.com.pictureparty/.partysharing }: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2507)
at android.app.ActivityThread.access$1900(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:193)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
at sytex.consulting.com.pictureparty.partysharing.handleStart(partysharing.java:65)
at sytex.consulting.com.pictureparty.partysharing.onStartCommand(partysharing.java:50)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2490)
... 10 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.objects.Serial.ListenInsecure(Serial.java:225)
at sytex.consulting.com.pictureparty.partysharing._service_start(partysharing.java:690)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
... 14 more
Caused by: java.io.IOException: Address already in use
at android.bluetooth.BluetoothSocket.throwErrnoNative(Native Method)
at android.bluetooth.BluetoothAdapter.listenUsingInsecureRfcommOn(BluetoothAdapter.java:1079)
... 21 more


Am I doing something wrong? Any help would be appreciated.

Thanks,

Gun
 
Last edited:
Top