Based on my research, this is not possible on standard Android devices, Samsung has achieved this with one of its applications, but this is most likely due to their improvement in the basic functions of Android. This will mean, however, that they will need to issue documentation on how this will be achieved, and this will only work on the phones on which they turned it on.
If someone has an answer that is really useful, and then clarifies why this cannot be done, I would be happy to accept it, I will leave it here, hoping that other people see it and do not waste time researching the subject until those since I did it.
* Edit if Google updates the OS in some way so that applications can check if the camera is being used, and if so, to free it, then it will work easily, but, alas, we have to wait for them. Or design on an iPhone where you don't need to contact the camera to access the flash.
source share