October 2018
Intermediate to advanced
464 pages
15h 17m
English
As you can see from the previous paragraphs, most of the code is related to finding and opening the camera to use the flash feature. setTorchMode() was introduced in API 23, which is why we have the API version check:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){}
This app demonstrates using the new camera2 libraries, which were introduced in Lollipop (API 21). Both the vibrate and ringtone methods have been available since API 1.
The getCameraId() method is where we check for the camera. We want an outward-facing camera with a flash. If one is found, the ID is returned; otherwise, it is null. If the camera id is null, we disable the button.
To play the sound, we use the Ringtone object from the RingtoneManager ...