src/com/btwiz/test/Tester.java
public static void connectToDevice(final Context context, final int major, 
			final String name, final SecureMode secureMode, final UUID serviceUuid) { 		
		try {
			if (!BTWiz.isEnabled(context)) {
				// TODO call startActivity with BTWiz.enableBTIntent() allowing user to enable BT
				return; 
			}
		} catch (DeviceNotSupportBluetooth e) {
			// TODO disable BT functionality in your app
			return; 
		}
		
		final IDeviceConnectionListener deviceConnectionListener = new IDeviceConnectionListener() {			
			@Override
			public void onConnectionError(Exception exception, String where) {
				// TODO handle connection error
				Log.e("Tester", "Connection error: " + exception + " at " + where);  
			}			
			@Override
			public void onConnectSuccess(BTSocket clientSocket) {
				// TODO work with new connection e.g. using
				// async IO methods: readAsync() & writeAsync()
				// or synchronous read() & write()
				Log.d("Tester", "Connected to new device"); 
			}
		}; 
		

		// declare a connecting listener
		IDeviceLookupListener lookupListener = new IDeviceLookupListener() {
			@Override
			public boolean onDeviceFound(BluetoothDevice device, boolean byDiscovery) {
				// log
				String name = device.getName();
				String addr = device.getAddress();
				int major = device.getBluetoothClass().getMajorDeviceClass();
				String majorStr = Utils.majorToString(major);
				Log.d("Tester", "Discovered device: " + name + ", " + addr + ", " + majorStr);				
				// and connect to the newly found device
				BTWiz.connectAsClientAsync(context, device, deviceConnectionListener, secureMode, serviceUuid); 
				return false; // and terminate discovery
			}
			@Override
			public void onDeviceNotFound(boolean byDiscovery) {
				// TODO handle discovery failure
				Log.d("Tester", "Failed to discover device"); 				
			}
		}; 
		 
		final boolean DISCOVER_IF_NEEDED = true; // start discovery if device not found in bonded-devices list 
		DeviceMajorComparator comparator = new DeviceMajorComparator(major, name);
		
		BTWiz.lookupDeviceAsync(context, comparator, lookupListener, DISCOVER_IF_NEEDED);
		
		// TODO call BTWiz.cleanup() at end of BT processing 
	}
/**
	 * Test looking up and connecting to a single device, identified by major number & name, via getBTDeviceAsync.
	 * Note that if device is not part of the bonded list a discovery process will be initiated.
	 *  Set name to null to disable comparison by name    
	 *  Set major to -1 to disable comparison by major    
	 */
Test looking up and connecting to a single device, identified by major number & name, via getBTDeviceAsync.
Note that if device is not part of the bonded list a discovery process will be initiated.
Set name to null to disable comparison by name
Set major to -1 to disable comparison by major
Test looking up and connecting to a single device identified by major number & name via getBTDeviceAsync . Note that if device is not part of the bonded list a discovery process will be initiated . Set name to null to disable comparison by name Set major to - 1 to disable comparison by major
public static void connectToDevice(final Context context, final int major, 
			final String name, final SecureMode secureMode, final UUID serviceUuid) { 		
		try {
			if (!BTWiz.isEnabled(context)) {
				return; 
			}
		} catch (DeviceNotSupportBluetooth e) {
			return; 
		}
		final IDeviceConnectionListener deviceConnectionListener = new IDeviceConnectionListener() {			
			@Override
			public void onConnectionError(Exception exception, String where) {
				Log.e("Tester", "Connection error: " + exception + " at " + where);  
			}			
			@Override
			public void onConnectSuccess(BTSocket clientSocket) {
				Log.d("Tester", "Connected to new device"); 
			}
		}; 
		IDeviceLookupListener lookupListener = new IDeviceLookupListener() {
			@Override
			public boolean onDeviceFound(BluetoothDevice device, boolean byDiscovery) {
				String name = device.getName();
				String addr = device.getAddress();
				int major = device.getBluetoothClass().getMajorDeviceClass();
				String majorStr = Utils.majorToString(major);
				Log.d("Tester", "Discovered device: " + name + ", " + addr + ", " + majorStr);				
				BTWiz.connectAsClientAsync(context, device, deviceConnectionListener, secureMode, serviceUuid); 
				return false; 
			}
			@Override
			public void onDeviceNotFound(boolean byDiscovery) {
				Log.d("Tester", "Failed to discover device"); 				
			}
		}; 
		final boolean DISCOVER_IF_NEEDED = true; 
		DeviceMajorComparator comparator = new DeviceMajorComparator(major, name);
		BTWiz.lookupDeviceAsync(context, comparator, lookupListener, DISCOVER_IF_NEEDED);
	}
public static void connectToDevice ( final Context context , final int major , final String name , final SecureMode secureMode , final UUID serviceUuid ) { try { if ( ! BTWiz . isEnabled ( context ) ) { return ; } } catch ( DeviceNotSupportBluetooth e ) { return ; } final IDeviceConnectionListener deviceConnectionListener = new IDeviceConnectionListener ( ) { @ Override public void onConnectionError ( Exception exception , String where ) { Log . e ( "Tester" , "Connection error: " + exception + " at " + where ) ; } @ Override public void onConnectSuccess ( BTSocket clientSocket ) { Log . d ( "Tester" , "Connected to new device" ) ; } } ; IDeviceLookupListener lookupListener = new IDeviceLookupListener ( ) { @ Override public boolean onDeviceFound ( BluetoothDevice device , boolean byDiscovery ) { String name = device . getName ( ) ; String addr = device . getAddress ( ) ; int major = device . getBluetoothClass ( ) . getMajorDeviceClass ( ) ; String majorStr = Utils . majorToString ( major ) ; Log . d ( "Tester" , "Discovered device: " + name + ", " + addr + ", " + majorStr ) ; BTWiz . connectAsClientAsync ( context , device , deviceConnectionListener , secureMode , serviceUuid ) ; return false ; } @ Override public void onDeviceNotFound ( boolean byDiscovery ) { Log . d ( "Tester" , "Failed to discover device" ) ; } } ; final boolean DISCOVER_IF_NEEDED = true ; DeviceMajorComparator comparator = new DeviceMajorComparator ( major , name ) ; BTWiz . lookupDeviceAsync ( context , comparator , lookupListener , DISCOVER_IF_NEEDED ) ; }
Test looking up and connecting to a single device, identified by major number & name, via getBTDeviceAsync.
Test looking up and connecting to a single device identified by major number & name via getBTDeviceAsync .
// TODO call startActivity with BTWiz.enableBTIntent() allowing user to enable BT // TODO disable BT functionality in your app // TODO handle connection error // TODO work with new connection e.g. using // async IO methods: readAsync() & writeAsync() // or synchronous read() & write() // declare a connecting listener // log // and connect to the newly found device // and terminate discovery // TODO handle discovery failure // start discovery if device not found in bonded-devices list  // TODO call BTWiz.cleanup() at end of BT processing 