They can’t and they don’t. Unless you see an orange or green light on your device, neither the camera nor the microphone is recording. So says Apple, Google, Samsung, and probably others, though implementations may vary.
Apple has now come up with a new way of protecting your privacy. Apparently, on the newest devices, a teeny little computer chip running its own operating system is watching the camera and microphone all the time, and it alone has control of the little lights. Your iPhone, iPad, or Mac has no access to those lights or the little chip guarding them.