Code example for BluetoothAdapter

Methods: cancelDiscoverylistenUsingRfcommWithServiceRecord

0
 
		} else if (mMethod == BLUETOOTH) {
			mBTSocket = null;
			// TODO check that 
			// Always cancel discovery because it will slow down a connection 
			mBTAdapter.cancelDiscovery();
 
			if (mAction == CONNECT) {
				mBTSocket = mBTDevice
						.createRfcommSocketToServiceRecord(MY_UUID);
				// Make a connection to the BluetoothSocket 
 
				// This is a blocking call and will only return on a 
				// successful connection or an exception 
				mBTSocket.connect();
 
				mInStream = mBTSocket.getInputStream();
				mOutStream = mBTSocket.getOutputStream();
			} else if (mAction == LISTEN) {
				// TODO First param seems useless ?? 
				// Create a new listening server socket 
				BluetoothServerSocket tmp = mBTAdapter
						.listenUsingRfcommWithServiceRecord("KTBDemo", MY_UUID);
				// TODO Global Variable for TIMEOUT 
				mBTSocket = tmp.accept(20000);
 
				mInStream = mBTSocket.getInputStream();
Contextual code suggestions in your IDE  Get Codota for Java