Wednesday, April 23, 2014

Neighborhoods Android Bluetooth serial development OutputStream to send data to fail.


Predecessors, I am new Bluetooth serial port this development, doing time data transmission. Been reported

java.io.IOException: [JSR82] write: write () failed. Mistakes, get half do not know what the problem.

I have the appropriate permissions added.



Seeking guidance on January grateful.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Amount, ask for replies ah
Reply:
Do not you see how the code ah, the first pairing, the connection is already paired device to select
Reply:
Estimates are problems connected, sending data is generally not a problem, unless the amount of data is too large
Reply:
reference to the second floor jack_wolf_ reply:
code on how you do not see ah, the first pair, the choice has been paired device to connect


socket = device.createRfcommSocketToServiceRecord (UUID
. FromString ("00001101-0000-1000-8000-00805F9B34FB"));

if (socket.isConnected ())
socket.close ();

/ / Cancel the search
if (mBtAdapter! = null) {
mBtAdapter.cancelDiscovery ();
}
socket.connect ();


boolean ss = socket.isConnected ();
progressDialog.dismiss ();

OutputStream os = socket.getOutputStream ();
String str = "fdfdfa050d0a";
os.write (hexStringToBytes (str));

When I tested this with a simple code, which also failed to send.

LOG follows:
04-17 10:40:17.128: E / connect (23390): java.io.IOException: [JSR82] write: write () failed
.04-17 10:40:17.128: E / connect (23390): at android.bluetooth.BluetoothSocket.write (BluetoothSocket.java: 702)
04-17 10:40:17.128: E / connect (23390): at android.bluetooth.BluetoothOutputStream.write (BluetoothOutputStream.java: 85)
04-17 10:40:17.128: E / connect (23390): at java.io.OutputStream.write (OutputStream.java: 82)
04-17 10:40:17.128: E / connect (23390): at com.mnhealth.TestSugar $ clientThread.run (TestSugar.java: 201)

System is android 4.2.2

Please help gets it. .
Reply:
reference to the third floor Mailbomb reply:
is estimated that the problem is connected, sending data is generally not a problem, unless the amount of data is too large
< / fieldset>
I think it is, because no matter what time socket.isContected are returned false, but socket.connect is not reported any abnormal data reception can be received normally.
Reply:
Now test down, restart the phone every time, even the first time be able to send, and then send it failed
Reply:
os.flush (); Try
Reply:
reference to the 7th floor libin88435 reply:
os.flush (); try

Thank you, has been resolved,
os.flush ();
os.close ();

No comments:

Post a Comment