Code example for BluetoothSocket

Methods: close, connect, getInputStream, getOutputStream, getRemoteDevice

0
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			Log.i(TAG, "Invocation target exception: createRfcommSocket.");
			e.printStackTrace();
		} 
		Log.i(TAG, "Got socket for device " + socket.getRemoteDevice());
		localAdapter.cancelDiscovery();
 
		Log.i(TAG, "Connecting socket...");
		try { 
			socket.connect();
			Log.i(TAG, "Socket connected.");
		} catch (IOException e) {
			try { 
				Log.e(TAG, "Failed to connect socket. ", e);
				socket.close();
				Log.e(TAG, "Socket closed because of an error. ", e);
			} catch (IOException eb) {
				Log.e(TAG, "Also failed to close socket. ", eb);
			} 
			return false; 
		} 
 
		try { 
			outStream = socket.getOutputStream();
			Log.i(TAG, "Output stream open.");
			inStream = socket.getInputStream();
			Log.i(TAG, "Input stream open.");
		} catch (IOException e) {
			Log.e(TAG, "Failed to create output stream.", e);
		} 
		return true;