public void startDiscovery(View view) {
   if (btadapter.isDiscovering()) {
     btadapter.cancelDiscovery();
   }
   btadapter.startDiscovery();
   startDiscoveryButton.setEnabled(false);
 }
 public void onStart() {
   super.onStart();
   btadapter = BluetoothAdapter.getDefaultAdapter();
   if (btadapter == null) {
     /* uh-oh.. no bluetooth module found! */
     Toast.makeText(this, "Sorry, no bluetooth module found!", Toast.LENGTH_SHORT);
     /* terminate the activity */
     finish();
   } else {
     if (!btadapter.isEnabled()) {
       startActivityForResult(
           new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_BLUETOOTH_ENABLE);
     } else {
       setup();
     }
   }
 }
 private void setup() {
   for (BluetoothDevice device : btadapter.getBondedDevices()) {
     devicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
   }
   IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
   registerReceiver(discoveryReceiver, filter);
   filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
   registerReceiver(discoveryReceiver, filter);
 }
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   dk.itu.android.bluetooth.BluetoothAdapter.SetContext(this);
   /* create the list view adapter */
   devicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
   /* get a reference to the list */
   ListView devicesListView = (ListView) findViewById(R.id.DevicesListView);
   /* set the adapter */
   devicesListView.setAdapter(devicesArrayAdapter);
   /* get a reference to the StartDiscoveryButton */
   startDiscoveryButton = (Button) findViewById(R.id.StartDiscoveryButton);
 }
 public void onDestroy() {
   btadapter.cancelDiscovery();
   unregisterReceiver(discoveryReceiver);
 }