1

Actually currently i am storing bluetooth Low energy device address in database. so at any time user can tap on listview and get the value from device. right now there is no mechanism to remove device (if device not in range(not found in scanning)). because we provide feature that user can get previous history value if device are not in range .so user tap on screen retrieve address from database and use

mBluetoothAdapter.getRemoteDevice(bleAddress);

method to retrieve BluetoothDevice object for further operation like connectgatt e.t.c. but according to google documentaion of getRemoteDevice(bleAddress)

return device object even if device is not in range according to google doc.

A BluetoothDevice will always be returned for a valid hardware address, even if this adapter has never seen that device.

so how do i check whether device is not in range. i can try to put timer for it but it is not good option please give me some more idea.

[UPDATE] ok i found some work around if i am try to connect already available device address which are not in range .so after some time android disconnected with status 133.

@Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status,
            int newState) {
            if(status==133){
                Intent intent=new Intent(FetchBluetoothCharacteristicService.DEVICE_NOT_RANGE);
                sendBroadcast(intent);
            }
            if (newState == BluetoothProfile.STATE_CONNECTED) {

                Log.d(TAG, "GATT DEVICE CONNECTED");
                Log.d(TAG,
                        "And Attempting to start service discovery:"
                                + gatt.discoverServices());
            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                close();
                Intent intent=new Intent(FetchBluetoothCharacteristicService.DEVICE_DISCONNECTED);
                intent.putExtra(COUNTER, counter);
                sendBroadcast(intent);
            }
    } 
mcd
  • 1,434
  • 15
  • 31

1 Answers1

0

Can you look at the RSSI to see if it is in range?

https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi%28%29

That would tell you the received signal strength of the device - or FALSE if it can't be found.

Terence Eden
  • 14,034
  • 3
  • 48
  • 89
  • Thanks for reply but if actually rssi value only retrieve if device are connected . Read the RSSI for a connected remote device. and because of android api problem . using start and stop scanning repeatedly to get rssi value. and again the result is not accurate – mcd Jan 09 '14 at 13:59
  • BLE advertising packets contain an RSSI value and you get those by scanning (not having an actual connection to a device). I'm not familiar with Android, so I don't know if or where you'd get those values, though. – Tim Tisdall Jan 10 '14 at 15:27
  • Actually you are right but in android device are not repeatedly broadcast. so we have to start and stop scanning repeatedly. so some time device take a time to broadcast device .. so i don't know how to manage this? – mcd Jan 11 '14 at 05:11
  • 1
    @mcd For all the android devices I used only Nexus 7 does not received repeated broadcast. All the others (including Nexus 4 and 5) can receive repeated broadcast. I have to write a timer to stop and start scanning to get my app work on Nexus7. – reTs Jan 14 '14 at 07:21