如何在Google Play服务中使用条形码检测开启手电筒? [英] How turn on flashlight using Barcode Detection in Google Play services?

查看:184
本文介绍了如何在Google Play服务中使用条形码检测开启手电筒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用Google Play服务重新实现Redlaser条形码扫描器。并面对手电筒的问题。 Android hardware.Camera 对象不能与 gms.vision 中的 CameraSource 共同使用。
是否有机会使用手电筒和Google条形码扫描仪?

I'm trying to reimplement Redlaser barcode Scanner using Google play services. And face to the problem with flashlight. Android hardware.Camera object can't be using in common with CameraSource from gms.vision. Is there any opportunity to working with flashlight and Google barcode scanner?

推荐答案

不确定我完全了解你的重新问,但我的做法是使用已经创建的mCamerSource对象和setFlashMode(),这对我来说很合适,因为我使用了一个按钮来切换闪光灯。

Not sure I fully get what you're asking but my approach to this was to use the already created mCamerSource Object and setFlashMode() from there, this worked for me as I used a button to toggle the flash.

在你的onCreate中添加这个或createCameraSource方法,就像在样本中一样 - >

In your onCreate add this or in createCameraSource method just like in the samples ->

mCameraSource = builder
            .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null)
            .build();

然后制作切换闪光灯的方法,希望这有助于您。

Then Make a method to toggle the flash, hope this helps.

private void ToggleFlash()
{
    fab_flash.startAnimation(spin_it);
    if(currentDrawalbe == FLASH_DEFAULT_STATE)
    {
        fab_flash.setImageResource(FLASH_TOGGLE_STATE);
        currentDrawalbe = FLASH_TOGGLE_STATE;
        mCameraSource.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    }
    else
    {
        fab_flash.setImageResource(FLASH_DEFAULT_STATE);
        currentDrawalbe = FLASH_DEFAULT_STATE;
        mCameraSource.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
    }
}

currentDrawable只是一个闪光灯图标,所以基本上如果图像是一个开启的闪光灯执行else子句,否则如果子句

The currentDrawable is just an image for the flash light icon, so basically if the image is a turned on flash light executes else clause otherwise if clause

这篇关于如何在Google Play服务中使用条形码检测开启手电筒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆