Latest Bluetooth Tutorial

alfcen

Well-Known Member
Licensed User
Longtime User
I have a Bluetooth module that connects perfectly to a Pocket PC running a B4PPC program alongside the serial library.

While no security is set in the BT module, the Android Bluetooth asks for pairing
and a numerical code. Neither the default code nor any other attempt succeeds.

Sorry, for my ignorance regarding Bluetooth, is there a means of dropping the paring request and go straight to connection without caring about security, or is this inherent to Android?
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Thanks a lot for the hint into the right direction.

Connection is successful with
Serial1.ConnectInsecure(Admin,connectedDevice.Mac,1)
Looks like RFCOMM channel 1 only is accepted, though.

Now, the chat activity throws an out-of-memory error after
sending a command 3 times without response.

Are there any further options besides "UTF8" here:
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
Not sure whether my BT module supports UTF8, but ASCII if
I am not mistaken.

If you do not see any problem with the Serial library, please do not
bother to reply, I will investigate further.

Thanks so much for always reacting so promptly.


Error Log:
B4X:
connected: true
Starting activity: Intent { flg=0x20000 cmp=anywheresoftware.b4a.samples.bluetooth/.chatactivity }
** Activity (main) Pause, UserClosed = false **
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@47b02c78

** Activity (chatactivity) Create, isFirst = true **
** Activity (chatactivity) Resume **
Displayed activity anywheresoftware.b4a.samples.bluetooth/.chatactivity: 371 ms (total 371 ms)
[url]https://droidsecurity.appspot.com/secure/xmlrpc[/url]
dvmMalloc(68297496/0x04122318): someone's allocating a huge buffer
Out of memory on a 68297496-byte allocation.
"Thread-9" daemon prio=5 tid=8 RUNNABLE
  | group="main" sCount=0 dsCount=0 s=N obj=0x4778a5a0 self=0x3d9830
  | sysTid=6588 nice=0 sched=0/0 cgrp=unknown handle=4036976
  at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:~168)
  at java.lang.Thread.run(Thread.java:1096)
threadid=8: thread exiting with uncaught exception (group=0x4001d7d8)
FATAL EXCEPTION: Thread-9
java.lang.OutOfMemoryError
   at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:168)
   at java.lang.Thread.run(Thread.java:1096)
  Force finishing activity anywheresoftware.b4a.samples.bluetooth/.chatactivity
** Activity (chatactivity) Pause, UserClosed = true **
** Activity (main) Resume **
Synergy async event, q = 4000, prim_base = 0520, event = 8036, len = 9
Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
Process anywheresoftware.b4a.samples.bluetooth (pid 6577) has died.
WIN DEATH: Window{47bc16c8 anywheresoftware.b4a.samples.bluetooth/anywheresoftware.b4a.samples.bluetooth.main paused=false}
Unexpected resume of com.android.launcher2 while already resumed in anywheresoftware.b4a.samples.bluetooth
[unregister] handle 0x789ac8 still locked (state=40000001)
!!! FAILED BINDER TRANSACTION !!!
Got RemoteException sending setActive(false) notification to pid 6577 uid 10120
Timed out waiting on IInputContextCallback
 
Upvote 0

alfcen

Well-Known Member
Licensed User
Longtime User
In regular mode I am now getting responses, though mainly squares rather than text strings

Anyway, this issue is not related to B4A but to my lack of networking knowledge. You showed me the right direction and I will do my homework now.

Thanks so much, Erel.
 
Upvote 0

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Erel

Just a quick note to say that I figured it out. Your example works great in regular mode, too. Thanks a lot for your help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…