Code example for BluetoothSocket

Methods: close, connect, getOutputStream

0
 
			// Blocking connect, for a simple client nothing else can 
			// happen until a successful connection is made, so we 
			// don't care if it blocks. 
			try { 
				btSocket.connect();
				Log.e(TAG,
						"BT connection established, data transfer link open."); 
			} catch (final IOException e) {
				Log.e(TAG, "Could not connect!", e);
				try { 
					btSocket.close();
				} catch (final IOException e2) {
					Log.e(TAG,
							"Unable to close socket during connection failure", 
							e2);
				} 
				return false; 
			} 
		} 
 
		if (outStream == null) {
			try { 
				outStream = btSocket.getOutputStream();
			} catch (final IOException e) {
				Log.e(TAG, "Output stream creation failed.", e);
				return false; 
			} 
		}