返回蓝牙设备的RSSI值时出现问题

时间:2012-04-12 23:18:19

标签: android bluetooth

我正在使用Eclipse开发一个Android应用程序来返回蓝牙设备的RSSI值。我修改了Android蓝牙聊天示例以满足我的需求,但是我在返回RSSI值时遇到了问题。在点击 Scan 按钮发现附近的设备后,它返回设备名称,设备地址,并且还假设返回RSSI值,而是为RSSI显示null

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);
            }
        }
    }
};

1 个答案:

答案 0 :(得分:0)

我意识到这已经很晚了但是,在这一行上, mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress() + getRssi()); 你不应该说getRssi(); 它应该是您的变量Rssi。 这就是我如何得到我的RSSI值。