Android 如何在我连接的地方一次读取多个设备的rssi值?

Android 如何在我连接的地方一次读取多个设备的rssi值?,android,bluetooth,bluetooth-lowenergy,android-4.3-jelly-bean,rssi,Android,Bluetooth,Bluetooth Lowenergy,Android 4.3 Jelly Bean,Rssi,我正在开发一个应用程序,我必须连接到Android 4.3上的蓝牙设备 我可以连接到BLE设备,并使用BluetoothGatt.readRemoteRssi()从设备读取RSSI 我想在我连接的地方一次读取多个设备的RSSI 但我只能读取上次连接的设备的RSSI 如果有两个BLE设备A和B。 我连接到设备A,并从中读取RSSI。 连接到设备B后,我可以从设备B读取RSSI。 但是它不读取设备A的RSSI,它只读取设备B的RSSI final Intent qintent = new Inten

我正在开发一个应用程序,我必须连接到Android 4.3上的蓝牙设备

我可以连接到BLE设备,并使用BluetoothGatt.readRemoteRssi()从设备读取RSSI

我想在我连接的地方一次读取多个设备的RSSI 但我只能读取上次连接的设备的RSSI

如果有两个BLE设备A和B。 我连接到设备A,并从中读取RSSI。 连接到设备B后,我可以从设备B读取RSSI。 但是它不读取设备A的RSSI,它只读取设备B的RSSI

final Intent qintent = new Intent(this, DeviceControl.class);
        devicelist.setOnItemClickListener(new OnItemClickListener() {

                    @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            HashMap<String, Object> select = (HashMap<String, Object>) devicelist.getItemAtPosition(arg2);
            String name = (String) select.get("name");
            String address = (String) select.get("address");
            qintent.putExtra(DeviceControl.EXTRAS_DEVICE_NAME, name);
            qintent.putExtra(DeviceControl.EXTRAS_DEVICE_ADDRESS, address);
            startActivity(qintent);
        }
    });
Main.java中,它列出了我连接的所有设备

当我单击列表上的设备时,它会将设备名称和地址传输到DeviceControl.java

final Intent qintent = new Intent(this, DeviceControl.class);
        devicelist.setOnItemClickListener(new OnItemClickListener() {

                    @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            HashMap<String, Object> select = (HashMap<String, Object>) devicelist.getItemAtPosition(arg2);
            String name = (String) select.get("name");
            String address = (String) select.get("address");
            qintent.putExtra(DeviceControl.EXTRAS_DEVICE_NAME, name);
            qintent.putExtra(DeviceControl.EXTRAS_DEVICE_ADDRESS, address);
            startActivity(qintent);
        }
    });
BluetoothLeService.java将连接到设备

public boolean connect(final String address) {
    if (mBluetoothAdapter == null || address == null) {
        Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
        return false;
    }
    if(mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress) 
            && mBluetoothGatt != null) {
        Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
        if(mBluetoothGatt.connect()) {
            mConnectionState = STATE_CONNECTING;                
            return true;
        }else {
            return false;
        }
    }
    final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
    if(device == null) {
        Log.w(TAG, "Device not found.  Unable to connect");
        return false;
    }
    mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
    Log.d(TAG, "Try to create a new connection");
    mBluetoothDeviceAddress = address;
    mConnectionState =STATE_CONNECTING;
    return true;
}
连接到设备后,我可以使用readRemoteRssi从设备读取RSSI

public void readRemoteRssi() {
    mBluetoothGatt.readRemoteRssi();
}
但它只读取我连接的最后一个设备的RSSI

当我看到日志时,它总是将onCharacteristicWritereadRemoteRssi()发送到我连接的最后一个设备

在我想读取RSSI或将特征写入值写入第一个设备之前,我应该将GATT或设备重新连接到第一个地址吗??


是否有其他方法读取我连接的所有设备的RSSI???

制作多个BluetoothGatt对象以分别连接多个设备,并逐个调用readRemoteRssi

例如,您应该能够将这些BluetoothGatt对象放入数组中

BluetoothGatt mBluetoothGatt1 = device1.connectGatt(this, false, mGattCallback);
BluetoothGatt mBluetoothGatt2 = device2.connectGatt(this, false, mGattCallback);

如何使多个BluetoothGatt对象分别连接多个设备?请参阅编辑,从2个单独的mac地址获取device1和device2谢谢!我已经将单独的mac地址存储到阵列中。但是MBluetothGATT1和设备1的类型是BluetoothGatt。它怎么能转向阵列??它像蓝牙关贸总协定吗??抱歉…我是新手。我是否需要使用mBluetoothAdapter1..getRemoteDevice(地址)??或者我只需要制作多个蓝牙GATT对象??感谢您的指导!!我制作了多个BluetoothGatt对象,它可以工作!!