Sagar Zala
Sagar Zala

Reputation: 5134

BluetoothSocket.isConnected issue

I have created an Android Application in that if my Android has a Bluetooth connection to my computer and I power down my computer, isConnected still returns true. Anyone know if this can be fixed?

I'm not sure if there's a Bluetooth heartbeat or not.

Upvotes: 1

Views: 294

Answers (1)

Pooja Rajendran C
Pooja Rajendran C

Reputation: 452

Try this.

    IntentFilter connectivityFilter = new IntentFilter();
    connectivityFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    connectivityFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    registerReceiver(bluetoothModeCheckingReceiver, connectivityFilter);



 private final BroadcastReceiver bluetoothModeCheckingReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
            // to do
        } else if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
           //  to do
        }
    }
};

Upvotes: 1

Related Questions