Code example for BluetoothAdapter

Methods: cancelDiscovery, getRemoteDevice, isEnabled

1
		log_v("setupConnection()"); 
		if (mBTAdapter == null) {
		    return false; 
		} 
		// We assume that bluetooth already has been enabled 
		if (!mBTAdapter.isEnabled()) {
			return false; 
		} 
		 
		pairingIntentFilter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
		pairingIntentFilter.addAction(BluetoothDevice.ACTION_CLASS_CHANGED);
		pairingIntentFilter.addAction(BluetoothDevice.ACTION_FOUND);
		pairingIntentFilter.addAction(BluetoothDevice.ACTION_NAME_CHANGED);
		mContext.registerReceiver(this, pairingIntentFilter);
		 
		this.mConnObject = null;
		this.connectedAs = ConnectedAs.None;
		this.done = false;
		 
		initiateConnection(); 
		 
		log_i("setupConnection() end"); 
		return true; 
	} 
	 
	private synchronized void initiateConnection() { 
		log_d("initiateConnection()"); 
		 
		mBTAdapter.cancelDiscovery();
		 
		acceptThread  = new AcceptThread(); 
		BluetoothDevice otherDevice = mBTAdapter.getRemoteDevice(mac);
		log_i("initiateConnection ("+otherDevice.getBondState()+")");
		connectThread = new ConnectThread(otherDevice); 
 
		connectToOtherDevice(); 
		startListeningForConnection();