Code example for BluetoothAdapter: Communicating over Bluetooth

Methods: getState, startDiscovery

0
          
         
    } 
     
    public void startDiscovery () { 
		bt.startDiscovery();
		tv2.setText("Scanning for devices ... ");
		pb.setVisibility(0);
		pairButton.setVisibility(8);
	} 
	 
	public void noDiscovery () { 
		tv1.setText("Turn Bluetooth on to connect your Textbuster device. ");
		tv2.setText("Bluetooth is disabled.");
		pb.setVisibility(8);
		pairButton.setVisibility(8);
	} 
	 
	public void foundDevice () { 
		pb.setVisibility(8);
		tv1.setText("Setup the connection with your Textbuster device. ");
		tv2.setText("Found device " + textbuster.getName() + " (" + textbuster.getAddress() + ")\n" 
		+ "Press Button to pair. " ); 
		pairButton.setVisibility(0);
	} 
	 
	protected void onDestroy() {  
		Log.i(TAG, "destroy");
		unregisterReceiver(receiver);
		super.onDestroy(); 
	} 
	public void onPause() 
	  { 
		Log.i(TAG, "pause");
		unregisterReceiver(receiver);
	    super.onPause(); 
	  } 
 
	 public void onResume() 
	  { 
		 Log.i(TAG, "resume");
	    registerReceiver(receiver, filter);
	    super.onResume(); 
	  } 
 
	private final BroadcastReceiver receiver = new BroadcastReceiver() {
		  
		public void onReceive(Context context, Intent intent) { 
			String action = intent.getAction(); 
	 
			if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
				Log.i(TAG, "Found"); 
				Log.i(TAG, "Intent: " + intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE).toString()); 
				 
				BluetoothDevice d = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
				 
				Log.i(TAG, "NAME: " + d.getName()); 
				 
				if (d.getName() != null) {  
					if (d.getName().equals("TEXTBUSTER")) { 
						textbuster = d; 
						foundDevice(); 
					} 
				} 
				 
				 
			}  
			  
			if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) { 
				Log.i(TAG, "Disc started"); 
			} 
	 
			if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { 
				if (textbuster==null) { 
					Log.i(TAG, "go again"); 
					startDiscovery(); 
				} 
			} 
			 
			if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { 
				Log.i(TAG, "State changed"); 
				 
				int state = bt.getState(); 
				 
				switch (state) { 
				case 11: {												// turning on 
					tv2.setText("Bluetooth is being turned on"); 
					pb.setVisibility(0);