0

I am developing a android application using Eclipse to return the RSSI values of a Bluetooth device. I have modified the Android Bluetooth Chat example to fit my needs, but I am having problems returning the RSSI value. After hitting the scan button to discover nearby devices it returns the device name, device address, and is also suppose to return the RSSI value but instead it says null for the RSSI.

if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
                mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress() + getRssi());

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @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);
           // Get the Bluetooth RSSI
            short Rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
            // If it's already paired, skip it, because it's been listed already
            // Added getRssi()
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
                mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress() + getRssi());
            }
        // When discovery is finished, change the Activity title
        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            setTitle(R.string.select_device);
            if (mNewDevicesArrayAdapter.getCount() == 0) {
                String noDevices = getResources().getText(R.string.none_found).toString();
                mNewDevicesArrayAdapter.add(noDevices);
            }
        }
    }
};
Abdul Rahman
  • 2,097
  • 4
  • 28
  • 36

2 Answers2

0

I haven't tried it myself, but maybe this SO answer will help:

https://stackoverflow.com/a/2361630/831918

Supposedly it is possible using the NDK. Good luck!

Community
  • 1
  • 1
javajavajavajavajava
  • 1,223
  • 2
  • 12
  • 20
0

This is how I am getting RSSI

String deviceRSSI = (intent.getExtras()).get(BluetoothDevice.EXTRA_RSSI).toString();

private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                String deviceRSSI = (intent.getExtras()).get(BluetoothDevice.EXTRA_RSSI).toString();

                btArrayAdapter.add(device.getName() + "\n" + device.getAddress() + "\n" + deviceRSSI);
                btArrayAdapter.notifyDataSetChanged();
            }

            if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) {

            } else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {

            }
        }
    };
AZ_
  • 21,688
  • 25
  • 143
  • 191