Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This thread runs during a connection with a remote device.
- * It handles all incoming and outgoing transmissions.
- */
- private class ConnectedThread extends Thread {
- private final BluetoothSocket mmSocket;
- private final LineNumberReader mmInStream;
- private final OutputStream mmOutStream;
- public ConnectedThread(BluetoothSocket socket) {
- Log.d(LOG_TAG, "create ConnectedThread");
- mmSocket = socket;
- LineNumberReader tmpIn = null;
- OutputStream tmpOut = null;
- // Get the BluetoothSocket input and output streams
- try {
- tmpIn = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
- tmpOut = socket.getOutputStream();
- } catch (IOException e) {
- Log.e(LOG_TAG, "temp sockets not created", e);
- }
- mmInStream = tmpIn;
- mmOutStream = tmpOut;
- }
- public void run() {
- Log.i(LOG_TAG, "BEGIN mConnectedThread");
- while(true) {
- try {
- String curScan = mmInStream.readLine();
- if (D) Log.i(LOG_TAG, "scan read in service: "+curScan);
- //////////////////////////////////////////////
- //TODO: send the read intent from here
- //////////////////////////////////////////////
- Intent i = new Intent(ScannerService.ACTION_READ_SCANNER);
- i.putExtra("scannerRead", curScan);
- sendBroadcast(i);
- } catch(IOException e) {
- connectionLost();
- break;
- }
- }
- }
- public void cancel() {
- try {
- mmSocket.close();
- } catch (IOException e) {
- Log.e(LOG_TAG, "close() of connect socket failed", e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement