Skip to Content
Android 9 Development Cookbook - Third Edition
book

Android 9 Development Cookbook - Third Edition

by Rick Boyer
October 2018
Intermediate to advanced
464 pages
15h 17m
English
Packt Publishing
Content preview from Android 9 Development Cookbook - Third Edition

How it works...

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Android Application Development Cookbook - Second Edition

Android Application Development Cookbook - Second Edition

Rick Boyer, Kyle Mew
Android High Performance Programming

Android High Performance Programming

Enrique López Mañas, Diego Grancini
Android Things Projects

Android Things Projects

Francesco Azzola

Publisher Resources

ISBN: 9781788991216Supplemental Content