Android Tutorial Android Bluetooth / BluetoothAdmin Tutorial

Status
Not open for further replies.

Andy Wu

Member
Licensed User
Longtime User
use blilt-in is ok,but using Bluetooth.zip to connect bluetooth will error.

and error message is "LastException.Message = java.io.IOException: read failed, socket might closed or timeout, read ret: -1"

I dont know how to slove this problem...
 

GMan

Well-Known Member
Licensed User
Longtime User
Do you use AsyncMode with or without PrefixMode ?
Try to change that
 

irda

Member
Licensed User
Longtime User
You cannot set the pin automatically. Note that once the device are paired they do not need to be paired again.

You can try to connect with ConnectInsecure. However you will need to find the correct port (usually between 1 to 10).

But, isn't there any way to set the pin without human intervention (paired programamatically)?
 

Beja

Expert
Licensed User
Longtime User
Connection is broken.
This is the message that pops up each time I try to receive response from other device.
Pairing is ok.
sending is ok.
the log is:

LogCat connected to: emulator-5554
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


java.lang.NullPointerException


at anywheresoftware.b4a.objects.Serial$BluetoothAdmin.IsEnabled(Serial.java:394)
at anywheresoftware.b4a.samples.bluetooth.main._activity_resume(main.java:324)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at anywheresoftware.b4a.samples.bluetooth.main.afterFirstLayout(main.java:104)
at anywheresoftware.b4a.samples.bluetooth.main.access$100(main.java:16)
at anywheresoftware.b4a.samples.bluetooth.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

p.s.
I used HC-6 BT module connected to PC.
Tried to remove the Prefix but no efeect.
Any help appreciated.
 

Beja

Expert
Licensed User
Longtime User
Thanks Erel,
I unzipped and run it without modification.. everything is fine except when trying to send some data back to the device.

main activity:
B4X:
    If FirstTime Then
        admin.Initialize("admin")
        serial1.Initialize("serial1")

ChatActivity:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("2")
    If AStream.IsInitialized = False Then
        AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
    End If
 

BETORRR

New Member
Licensed User
Longtime User
Please help me!

I NEED to use bluetooth because my work. I'm trying example bluetooth but ALWAYS recive this messge: Service Discovery Fail
I make Erel say -uncomment - Serial1 but don't work.
Help!
 

enrique1

Member
Licensed User
Longtime User
Hi All,

is it possible to get the battery level from a bluetooth connected device? I mean, the other device hasn't got installed an app and it cannot send this information, only allow to the other device connect to him.

Thanks in advice, I think this question has not posted before.
 

Kevin L. Johnson

Member
Licensed User
Longtime User
bluetooth com



thanks Jonas that worked like a charm, thanks much buddy!

cheers,
Walter

Walter, Jonas, Thanks to both of you for raising and solving the issue!
I had the same issue with a Sparkfun Bluetooth RNBT-25D3 and...
B4X:
'Switching 
   'AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
'to...
   AStream.Initialize(Main.serial1.InputStream, Main.serial1.OutputStream, "AStream")
also worked like a charm.
Thanks to Erel and Anywhere software for a great product and a great community too!
Kevin
 

Dogbonesix

Active Member
Licensed User
Longtime User
Problem Connecting with the BlueTooth tutorial - first try.
I was able to Pair my Cell Phone and Acer Tablet. Search for devices finds my tablet. But when I select "Choose device to connect" all I get is connection: false. So, I downloaded a BlueTooth Chat program from the play store to see if it will work - it does. What can go wrong with (line 85) serial1.Connect(connectedDevice.Mac)? The log shows - java.io.IOException:read failed, socked might be closed or timeout, read ret: -1 but that does not help me much. And insight will be greatly appreciated.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…