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; 
		} 
 
		try { 
			outStream = btSocket.getOutputStream(); // warning: may not be connected yet
		} catch (final IOException e) {
			Log.e(TAG, "Output stream creation failed.", e);
			return false; 
		} 
		Log.d(TAG, "Connected to Bluetooth");