I use Bluetooth Low Energy to connect to my Galaxy S4. After connecting, the connection status will be updated in the function
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String intentAction; if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) { Log.d(TAG,"Connected"); } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) { Log.d(TAG,"Disconnected"); } } }
In which status is obtained from
// Implements callback methods for GATT events that the app cares about. For example, // connection change and services discovered. private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { String intentAction; if (newState == BluetoothProfile.STATE_CONNECTED) { intentAction = ACTION_GATT_CONNECTED; mConnectionState = STATE_CONNECTED; broadcastUpdate(intentAction); Log.i(TAG, "Connected to GATT server."); // Attempts to discover services after successful connection. Log.i(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices()); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { intentAction = ACTION_GATT_DISCONNECTED; mConnectionState = STATE_DISCONNECTED; Log.i(TAG, "Disconnected from GATT server."); broadcastUpdate(intentAction); } }
However, ACTION_GATT_DISCONNECTED
takes 10 seconds to update when the connection between the BLE device and the phone is lost. In the case of ACTION_GATT_CONNECTED
it updates so fast for about 1 second. Is it possible to reduce the shutdown status in BLE? Thank you all
source share