Code example for BluetoothDevice

Methods: getAddress

0
            String action = intent.getAction();
            if (intent.getExtras() != null) {
                BluetoothDevice device = (BluetoothDevice) intent.getExtras()
                        .get(BluetoothDevice.EXTRA_DEVICE);
                Log.d(TAG, "Received broadcast: " + action);
                if (device != null && address.equals(device.getAddress())) {
                    if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
                        Log.d(TAG, "Connected -> Start service.");
                        sendIntent(context, true);
                    } 
                    if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED
                            .equals(action)
                            || BluetoothDevice.ACTION_ACL_DISCONNECTED
                                    .equals(action)) {
                        Log.d(TAG, "Disconnected -> Stop service.");
                        sendIntent(context, false);
                    } 
                } 
            } 
        } 
    }