[Android M Feature Spotlight] The Low-Power Doze Mode Can Be Turned On And Off On A Per-App Basis
[Android M Feature Spotlight] A Swipe From The Left On The Lock Screen Now Launches Google Voice Search Instead Of The Dialer
[Android M Feature Spotlight] Android Now Has A Native Flashlight API, Hopefully Negating The Need For OEM-Specific Solutions
[Android M Feature Spotlight] Bluetooth Low Energy Scanning By Apps Gets More Power Efficient
[Android M Feature Spotlight] Bluetooth Scanning Joins WiFi To Improve Location Accuracy
- View All 77 Articles In This Series
While Android Lollipop added a flashlight toggle into Quick Settings, circumventing most third-party torch apps, the function was only accessible in the notification drop-down and as an on/off switch. If you wanted to use the flashlight with morse code, for signaling, or other patterns, you still had to use a separate application and developers of said apps didn't have any clear API to build their software on. They had to hack together solutions for various phones, relying on whatever way the different OEMs had created to access the camera's flash.
With Android M, a new Flashlight API is accessible to developers with CameraManager.setTorchMode(). The flash will be switched on until the app is closed, it is toggled off, or some other app takes over control — flash isn't restricted or exclusive to any apps.
Developers can also check the flashlight's status with CameraManager.registerTorchCallback(), and code actions that get triggered when the mode changes with CameraManager.TorchCallback.onTorchModeChanged().
Here's the relevant part (starting at 29:01) of the What's New in Android talk at I/O 2015:
Alternative title: Writing Flashlight Apps For Android Is No Longer Torch-ure
- M Developer Preview API Overview