src/com/btwiz/library/BTWiz.java
public static void connectAsClientAsync(final Context context, final BluetoothDevice device, 
			final IDeviceConnectionListener connectionListener, final SecureMode secureMode, final UUID user_serviceUuid) {
		new Thread() {
			public void run() {
				boolean connected;
				BluetoothSocket sock;
				UUID serviceUuid = user_serviceUuid;
				if (serviceUuid != null) {
					sock = createClientSocket(device, connectionListener, secureMode, serviceUuid);
					if (sock == null) {
						connectionListener.onConnectionError(null, "createClientSocket");
						return; // operation failed
					} 
					connected = innerConnectAsClient(context, connectionListener, sock);
					if (!connected) {
						connectionListener.onConnectionError(null, "ConnectAsClient");
						return; // operation failed
					}
					// else: success
				}
				else {
					UUID[] uuids = getSupportedUuids(context, device);
					if (uuids != null && uuids.length > 0) {
						serviceUuid = uuids[0]; 
						sock = createClientSocket(device, connectionListener, secureMode, serviceUuid);
						if (sock != null) {
							connected = innerConnectAsClient(context, connectionListener, sock);
							if (connected) {
								return; // success
							}
						}
					}
					
					// failover 1: use DEFAULT_SPP_UUID 
					sock = createClientSocket(device, connectionListener, secureMode, DEFAULT_SPP_UUID);
					if (sock != null) {
						connected = innerConnectAsClient(context, connectionListener, sock);
						if (connected) {
							return; // success
						}
					}
					
					// failover 2: use createRfcommSocket via reflection 
					sock = createRfcommSocketViaReflection(device, secureMode);
					if (sock == null) {
						connectionListener.onConnectionError(null, "createRfcommSocket");
						return; // failed
					}
					connected = innerConnectAsClient(context, connectionListener, sock);
					if (!connected) {
						connectionListener.onConnectionError(null, "ConnectAsClient");
						return; // failed
					}
					// else: success
				}				
			}				

		}.start();
	}
/**
	 * Create a BT socket and connect to a remote BT device (server).
	 * 
	 * The secureMode param controls the type of RFC socket created i.e. weather 
	 * createRfcommSocketToServiceRecord or createInsecureRfcommSocketToServiceRecord services will be called.
	 *   
	 * Spawns a dedicated connect thread 
	 */
Create a BT socket and connect to a remote BT device (server).

The secureMode param controls the type of RFC socket created i.e. weather
createRfcommSocketToServiceRecord or createInsecureRfcommSocketToServiceRecord services will be called.

Spawns a dedicated connect thread
Create a BT socket and connect to a remote BT device ( server ) . The secureMode param controls the type of RFC socket created i . e . weather createRfcommSocketToServiceRecord or createInsecureRfcommSocketToServiceRecord services will be called . Spawns a dedicated connect thread
public static void connectAsClientAsync(final Context context, final BluetoothDevice device, 
			final IDeviceConnectionListener connectionListener, final SecureMode secureMode, final UUID user_serviceUuid) {
		new Thread() {
			public void run() {
				boolean connected;
				BluetoothSocket sock;
				UUID serviceUuid = user_serviceUuid;
				if (serviceUuid != null) {
					sock = createClientSocket(device, connectionListener, secureMode, serviceUuid);
					if (sock == null) {
						connectionListener.onConnectionError(null, "createClientSocket");
						return; 
					} 
					connected = innerConnectAsClient(context, connectionListener, sock);
					if (!connected) {
						connectionListener.onConnectionError(null, "ConnectAsClient");
						return; 
					}
				}
				else {
					UUID[] uuids = getSupportedUuids(context, device);
					if (uuids != null && uuids.length > 0) {
						serviceUuid = uuids[0]; 
						sock = createClientSocket(device, connectionListener, secureMode, serviceUuid);
						if (sock != null) {
							connected = innerConnectAsClient(context, connectionListener, sock);
							if (connected) {
								return; 
							}
						}
					}
					sock = createClientSocket(device, connectionListener, secureMode, DEFAULT_SPP_UUID);
					if (sock != null) {
						connected = innerConnectAsClient(context, connectionListener, sock);
						if (connected) {
							return; 
						}
					}
					sock = createRfcommSocketViaReflection(device, secureMode);
					if (sock == null) {
						connectionListener.onConnectionError(null, "createRfcommSocket");
						return; 
					}
					connected = innerConnectAsClient(context, connectionListener, sock);
					if (!connected) {
						connectionListener.onConnectionError(null, "ConnectAsClient");
						return; 
					}
				}				
			}				
		}.start();
	}
public static void connectAsClientAsync ( final Context context , final BluetoothDevice device , final IDeviceConnectionListener connectionListener , final SecureMode secureMode , final UUID user_serviceUuid ) { new Thread ( ) { public void run ( ) { boolean connected ; BluetoothSocket sock ; UUID serviceUuid = user_serviceUuid ; if ( serviceUuid != null ) { sock = createClientSocket ( device , connectionListener , secureMode , serviceUuid ) ; if ( sock == null ) { connectionListener . onConnectionError ( null , "createClientSocket" ) ; return ; } connected = innerConnectAsClient ( context , connectionListener , sock ) ; if ( ! connected ) { connectionListener . onConnectionError ( null , "ConnectAsClient" ) ; return ; } } else { UUID [ ] uuids = getSupportedUuids ( context , device ) ; if ( uuids != null && uuids . length > 0 ) { serviceUuid = uuids [ 0 ] ; sock = createClientSocket ( device , connectionListener , secureMode , serviceUuid ) ; if ( sock != null ) { connected = innerConnectAsClient ( context , connectionListener , sock ) ; if ( connected ) { return ; } } } sock = createClientSocket ( device , connectionListener , secureMode , DEFAULT_SPP_UUID ) ; if ( sock != null ) { connected = innerConnectAsClient ( context , connectionListener , sock ) ; if ( connected ) { return ; } } sock = createRfcommSocketViaReflection ( device , secureMode ) ; if ( sock == null ) { connectionListener . onConnectionError ( null , "createRfcommSocket" ) ; return ; } connected = innerConnectAsClient ( context , connectionListener , sock ) ; if ( ! connected ) { connectionListener . onConnectionError ( null , "ConnectAsClient" ) ; return ; } } } } . start ( ) ; }
Create a BT socket and connect to a remote BT device (server).
Create a BT socket and connect to a remote BT device ( server ) .
// operation failed // operation failed // else: success // success // failover 1: use DEFAULT_SPP_UUID  // success // failover 2: use createRfcommSocket via reflection  // failed // failed // else: success