Java Code Examples for android.bluetooth.BluetoothSocket#getInputStream()

The following examples show how to use android.bluetooth.BluetoothSocket#getInputStream() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public ConnectedThread(BluetoothSocket socket) {
            mmSocket = socket;
            bluetoothSocket = socket;
            InputStream tmpIn = null;
            OutputStream tmpOut = null;
            // Get the input and output streams, using temp objects because
            // member streams are final
            try {
                tmpIn = socket.getInputStream();
                tmpOut = socket.getOutputStream();
            } catch (IOException e) {
//                Log.d("ConnectedThread", e.getMessage());
            }

            mInputStream = tmpIn;
            mOutputStream = tmpOut;
        }
 
Example 2
Source Project: DataLogger   File: BluetoothConnectionHelper.java    License: MIT License 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, int index) {
//            Log.d(TAG, "create ConnectedThread");
            mmSocket = socket;
            mIndex = index;
            InputStream tmpIn = null;
            OutputStream tmpOut = null;

            // Get the BluetoothSocket input and output streams
            try {
                tmpIn = socket.getInputStream();
                tmpOut = socket.getOutputStream();
            } catch (IOException e) {
                Log.e(TAG, "::ConnectedThread Input/Output stream sockets not created", e);
            }

            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        }
 
Example 3
private void manageConnectedSocket(BluetoothSocket socket) throws IOException {
    synchronized (this) {
        os = socket.getOutputStream();
    }

    is = socket.getInputStream();
    //noinspection InfiniteLoopStatement
    while (true) {
        // While loop will terminate only upon an actual IOException
        // or upon a close of the socket that will also cause an IOException.
        int didRead = is.read(buffer);
        //noinspection StatementWithEmptyBody
        if (didRead > 0) {
            // TODO
        }
    }
}
 
Example 4
Source Project: retroband   File: BluetoothManager.java    License: Apache License 2.0 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    Log.d(TAG, "create ConnectedThread");
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 5
public ConnectedThread(BluetoothSocket socket, String socketType) {
    Log.d(TAG, "create ConnectedThread: " + socketType);
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
    mState = STATE_CONNECTED;
}
 
Example 6
public ConnectedThread(BluetoothSocket socket) {
    Log.d(TAG, "create ConnectedThread: ");
    mSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mInputStream = tmpIn;
    mOutputStream = tmpOut;
}
 
Example 7
BtWorkerThread(BluetoothSocket socket, String socketType)
{
	log.log(Level.FINE, "create BtWorkerThread: " + socketType);
	mmSocket = socket;
	InputStream tmpIn = null;
	OutputStream tmpOut = null;

	// Get the BluetoothSocket input and output streams
	try
	{
		tmpIn = socket.getInputStream();
		tmpOut = socket.getOutputStream();
	} catch (IOException e)
	{
		log.log(Level.SEVERE, "temp sockets not created", e);
	}

	mmInStream = tmpIn;
	mmOutStream = tmpOut;
	// set streams
	ser.setStreams(mmInStream, mmOutStream);
}
 
Example 8
public ConnectedThread(BluetoothSocket socket, Handler handler) {
    mmSocket = socket;
    mHandler = handler;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the input and output streams, using temp objects because
    // member streams are final
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) { }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 9
Source Project: libcommon   File: BluetoothManager.java    License: Apache License 2.0 6 votes vote down vote up
public ReceiverThread(final BluetoothSocket socket) {
			super("ReceiverThread:" + mName, socket);
//			if (DEBUG) Log.d(TAG, "create ReceiverThread:");
			InputStream tmpIn = null;
			OutputStream tmpOut = null;

			// 受信待ち用のInputStreamと送信用のOutputStreamを取得する
			// 普通のInputStreamはBufferedInputStreamで、OutputStreamは
			// BufferedOutputStreamでラップするけどここで取得されるStreamを
			// ラップすると上手く動かないみたい
			try {
				tmpIn = socket.getInputStream();
				tmpOut = socket.getOutputStream();
			} catch (final IOException e) {
				Log.e(TAG, "temp sockets not created", e);
			}

			mmInStream = tmpIn;
			mmOutStream = tmpOut;
		}
 
Example 10
Source Project: retrowatch   File: BluetoothManager.java    License: Apache License 2.0 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    Log.d(TAG, "create ConnectedThread");
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 11
public ConnectedThread(BluetoothSocket socket)
{
	Log.d(TAG, "create ConnectedThread");
	mmSocket = socket;
	InputStream tmpIn = null;
	OutputStream tmpOut = null;

	try
	{
		tmpIn = socket.getInputStream();
		tmpOut = socket.getOutputStream();
	}
	catch (IOException e)
	{
		Log.e(TAG, "temp sockets not created", e);
	}

	mmInStream = tmpIn;
	mmOutStream = tmpOut;
}
 
Example 12
Source Project: Android-HC05-App   File: BluetoothService.java    License: MIT License 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the input and output streams, using temp objects because
    // member streams are final
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(Constants.TAG, "Temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 13
Source Project: Makeblock-App-For-Android   File: Bluetooth.java    License: MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket){
	mmSocket = socket;
	mRx = new ArrayList<Byte>();
	InputStream tmpIn = null;
	OutputStream tmpOut = null;
	
	try {
		tmpIn = socket.getInputStream();
		tmpOut = socket.getOutputStream();
	} catch (IOException e) {
		e.printStackTrace();
	}
	mmInStream = tmpIn;
	mmOutStream = tmpOut;
}
 
Example 14
static void sendPacket(BluetoothSocket socket, byte[] data) throws IOException, InterruptedException {
        OutputStream o = socket.getOutputStream();
        InputStream i = socket.getInputStream();
        byte[] packet = new byte[data.length + 3];
        packet[0] = 0x3e;
        packet[packet.length - 1] = 0x3c;
        byte crc = 0;
        for (int j = 0; j < data.length; j++) {
            crc += data[j];
            packet[j + 1] = data[j];
        }
        packet[packet.length - 2] = crc;
        o.write(packet);

        byte[] buffer = new byte[256];
        Date date = new Date();
        while (new Date().getTime() - date.getTime() < 200) {
            if (i.available() > 0) {
                int r = i.read(buffer);
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < r; j++) {
                    sb.append(String.format(" %02x", buffer[j]));
                }
//                Log.i(TAG, "Read: " + r + " bytes:" + sb);
                break;
            }
            Thread.sleep(50);
        }
    }
 
Example 15
private String listenForMessages(BluetoothSocket socket,
                                 StringBuilder incoming) {
  String result = "";
  mListening = true;

  int bufferSize = 1024;
  byte[] buffer = new byte[bufferSize];

  try {
    InputStream instream = socket.getInputStream();
    int bytesRead = -1;
    while (mListening) {
      bytesRead = instream.read(buffer);
      if (bytesRead != -1) {
        while ((bytesRead == bufferSize) && (buffer[bufferSize-1] != 0)) {
          result = result + new String(buffer, 0, bytesRead - 1);
          bytesRead = instream.read(buffer);
        }

        result = result + new String(buffer, 0, bytesRead - 1);
        incoming.append(result);
      }
    }
  } catch (IOException e) {
    Log.e(TAG, "Message receive failed.", e);
  }
  return result;
}
 
Example 16
Source Project: Chorus-RF-Laptimer   File: BluetoothService.java    License: MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, String socketType) {
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) { }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 17
Source Project: AndroidDemo   File: BluetoothChatService.java    License: MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket bluetoothSocket) {
            this.bluetoothSocket = bluetoothSocket;
            try {
                inputStream = bluetoothSocket.getInputStream();
                outputStream = bluetoothSocket.getOutputStream();
            } catch (IOException e) {
//                e.printStackTrace();
            }
        }
 
Example 18
Source Project: GodotBluetooth   File: GodotBluetooth.java    License: MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket newSocket) {

            InputStream tmpIn = null;
            OutputStream tmpOut = null;

            try {
                tmpIn = newSocket.getInputStream();
                tmpOut = newSocket.getOutputStream();
            } catch (IOException e) { }

            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        }
 
Example 19
public ConnectedThread(BluetoothSocket socket, String socketType) {
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) { }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 20
Source Project: nxt-remote-control   File: NXTTalker.java    License: Apache License 2.0 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;
    
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}