简体   繁体   English

Android : 如何使用 Camera Source Builder 以编程方式打开/关闭手电筒?

[英]Android : How to turn flashlight on/off programmly using Camera Source Builder?

i made Camera Preview using CameraSource in Android Studio我在 Android Studio 中使用 CameraSource 制作了相机预览

new CameraSource.Builder(this , detector).setAutoFocusEnabled(true).build();

as you can see i easliy set the Auto Focus Enabled.如您所见,我很容易将自动对焦设置为启用。

i was just wondering if there is an easy way to enable/disable flashlight ?我只是想知道是否有一种简单的方法可以启用/禁用手电筒?

Just use this method:只需使用此方法:

.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH).build();

Edit:编辑:

This class was deprecated in API level 21. Google recommends using the new android.hardware.camera2 API for new applications.此类在 API 级别 21 中已弃用。Google 建议对新应用程序使用新的 android.hardware.camera2 API。

In this thread you can see how to use: Turning on/off flash with Android camera2 API not working在此线程中,您可以看到如何使用: Turning on/off flash with Android camera2 API not working

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM