有人可以建议如何在Android API Level 18+上持续读取BT4-LE信号强度,以检测BT-LE信标的相对接近度?我知道在扫描过程中会返回LE无线电信号强度(参见:http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback.html),但是一旦完成扫描并建立了连接,无论如何都要获得更新的BT-LE信号强度而不重新扫描?
答案 0 :(得分:9)
http://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi()
异步调用以开始读取信号强度。
读取完成后回调。
阅读前需要连接。
答案 1 :(得分:1)
if(newState == BluetoothProfile.STATE_CONNECTED)
{
TimerTask task = new TimerTask()
{
@Override
public void run()
{
mBluetoothGatt.readRemoteRssi();
}
};
Timer rssiTimer = new Timer();
rssiTimer.schedule(task, 1000, 1000);
}
答案 2 :(得分:0)
在调用readRemoteRssi()读取信号强度之前,需要先连接。 示例代码:
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {
// TODO Auto-generated method stub
String intentAction;
if(newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
mBluetoothGatt.readRemoteRssi();