Try {
//by UUID to monitor the request, and then get to the corresponding service interface
ServerSocket=mBluetoothAdapter
ListenUsingRfcommWithServiceRecord (NAME, MY_UUID);
} the catch (Exception e) {
e.printStackTrace();
Re_ms. SetText (" failure ");
}
//socket. The connect ();
}
Public void the run () {
Try {
//serverSocket. Close ();
//receive the client interface
The socket=serverSocket. The accept ();
//get the input stream
Re_msg. SetText (" ceshi ");
//is=socket. GetInputStream ();
Is=socket. GetInputStream ();
OS=socket. GetOutputStream ();
//serverSocket. Close ();
Re_msg. SetText (" ceshi ");
//get to the output stream
//OS=socket. GetOutputStream ();
//wireless loop to receive data
While (true) {
//create a 128 - byte buffer
Byte [] buffer=new byte [128].
//each read 128 bytes, and save the read the Angle of the standard
Int count=is. The read ();
//create the Message class, send data to the handler
The Message MSG=new Message ();
//send a String of data, let he upcasting obj type
MSG. Obj=new String (buffer, 0, count, "utf-8");
//send data
Handler. SendMessage (MSG);
//re_msg setText (a);
}
} the catch (Exception e) {
//TODO: handle the exception
Re_msg. SetText (" failure ");
e.printStackTrace();
}
}
}
This is threaded programs, you can't get a data, using bluetooth has been parked in the socket=serverSocket. The accept (); , the debug view sockets=null, bluetooth connection, can realize the function of sending data, found two days but could not find a solution, everyone a great god genuflect is begged to give directions, thank!
CodePudding user response:
have good people to teach it to meCodePudding user response:
You two are asynchronous, permission to apply for itIf two are asynchronous, you have to wait until AcceptThread completes to implement the run method, otherwise must be null
CodePudding user response:
You don't have to send data to successCodePudding user response:
The same problem, has been aceept is nil