Code example for BluetoothSocket

Methods: connect, getRemoteDevice

0
		{ 
			try  
			{ 
				// Connect the device through the socket. This will block 
				// until it succeeds or throws an exception 
				mmSocket.connect();
 
			}  
			catch (IOException connectException) 
			{ 
				// Unable to connect; close the socket and get out 
				Log.e(TAG,
						"Unable to connet to: "+mmDevice.getName()+", trying to close the socket: "
						+ connectException.getMessage());
				 
				connectException.printStackTrace();
 
				 
				mobitradeProtocol.setExceptionOccuredOnSession(mmSocket.getRemoteDevice());
				 
				return; 
			} 
 
			// Do work to manage the connection (in a separate thread) 
			manageConnectedSocket(mmSocket);
		}else 
		{ 
			mobitradeProtocol.setExceptionOccuredOnSession(mmSocket.getRemoteDevice());
		} 
	} 
 
	public void manageConnectedSocket(BluetoothSocket sock) 
	{ 
		String adr = mmDevice.getAddress();
		mobitradeProtocol.SetExchangeThreadForSession(adr, new ExchangeWithMobiTradeDevice(mobitradeProtocol, sock));
 
		// Start the exchanging thread to read the received messages 
		// Sending the list of channels 
 
		mobitradeProtocol.StartExchangeThreadForSession(adr);