Attached is the class Camera2Torch. It uses B4A's Camera2 library to use Android's CameraManager's setTorchMode method. Please note that this method is only available since API23, whereas CameraManager is available as of API21.
This has been successfully tested (via sideloading, targetSdkVersion="30") on the following:
Note:
With sideloading the app, no additional Manifest entries seem to be required, nor do I need to ask the user for permission to use the camera. I do not know if this changes for apps on Google's Play Store. Various internet posts on the subject of the usage of setTorchMode have the additional Manifest entries
Android Docs link for setTorchMode:
This has been successfully tested (via sideloading, targetSdkVersion="30") on the following:
- Pixel 7 running Android 13
- Chinese phone running Android 11
- Chinese phone running Android 6
Note:
With sideloading the app, no additional Manifest entries seem to be required, nor do I need to ask the user for permission to use the camera. I do not know if this changes for apps on Google's Play Store. Various internet posts on the subject of the usage of setTorchMode have the additional Manifest entries
- AddPermission("android.permission.FLASHLIGHT")
- AddManifestText(<uses-feature android:name="android.hardware.camera.flash" />)
Android Docs link for setTorchMode: