android : bluetooth support

Posted by Puneet kaur on Stack Overflow See other posts from Stack Overflow or by Puneet kaur
Published on 2010-03-22T09:22:03Z Indexed on 2010/03/22 9:51 UTC
Read the original article Hit count: 396

Filed under:
|
|

i have coded for bluetooth via defining a user task ,which will search the devices in background and set the list on foreground after finishing the search . but sometimes i am getting the data in adapter as "nodevice" "device1" "device2" ...... the problem here is why it is always filling the no device in the list and after that fill the device in list ..

private BroadcastReceiver mBlueToothInfoDiscoveryListener = new BroadcastReceiver() {
  /**
   * This is an overridden function called by the framework whenever there
   * is some broadcast message for Bluetooth info discovery listener
   */
  @Override
  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
      // Get the BluetoothDevice object from the Intent
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
      // If it's already paired, skip it, because it's been listed
      // already
      if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
        mNewBtDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
      }
      // When discovery is finished, change the Activity title
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
      setProgressBarIndeterminateVisibility(false);
      setTitle("device list");
      if (mNewBtDevicesArrayAdapter.getCount() == 0) {
        String noDevices = "No devices found";
        mNewBtDevicesArrayAdapter.add(noDevices);
      }
    }
  }
};

but here why it is sometimes going into else option on start and filling the list with no device then to if part again ... when devices are already on .

© Stack Overflow or respective owner

Related posts about android

Related posts about bluetooth