Code example for BluetoothAdapter

Methods: isEnabled, listenUsingRfcommWithServiceRecord

0
		private BluetoothServerSocket serverSocket;
		final static String NAME = "warrior";
		private IServerClosed serverClosed;
		public void createListeningSocket()throws Exception 
		{ 
			if(!btAdapter.isEnabled())
			{ 
				throw new Exception();
			} 
			serverSocket = btAdapter.listenUsingRfcommWithServiceRecord(NAME, UUID_RFCOMM_GENERIC);
			execute();
		} 
		protected Void doInBackground(Void... params) {
			try { 
				// the server wait to connected with time out of 20 sec 
				sSocket = serverSocket.accept(TIME_OUT);
				// iharel: serverSocket = null; 
				if (sSocket != null) {
					// cancel the scanning because is slowly the connection 
					serverSocket.close();
					btAdapter.cancelDiscovery();