如何以编程方式把火炬闪光灯上闪光灯、方式

2023-09-07 05:03:05 作者:我們的班主任妳威武雄壯!

我用LG擎天柱3D模型,我能打开手电筒,当我将相机切换到视频录制模式。在正常拍摄模式下,我只能打开闪光灯。

I am using LG Optimus 3D model, I am able to turn on the torch light when I switch the camera to video recording mode. In normal capture mode, I am only able to turn on flash light.

我通过添加不同的参数到Camera对象尝试了几种方式,但他们没有工作。我的code是如下:

I have tried several way by adding different parameters into the Camera object, but none of them work. My code is as below:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flash_light);



    PackageManager pm = getPackageManager();

    if (! pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)){
        Toast.makeText(this, "Your phone does not have flash light support.", Toast.LENGTH_LONG).show();
        finish();
    }

    camera = Camera.open(); 
    cParameters = camera.getParameters();



    cParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(cParameters);

}

没有一点我不能把它编程,我已检查如下,以确保我的手机支持手电筒模式,其实我真的能打开我的设备。

No point I cannot turn it on programmatically, I have checked as below to ensure my phone support torch mode, in fact, I am really able to turn on for my device.

List<String> abc = cParameters.getSupportedFlashModes();

        for (String a : abc){
            Log.d("mode: ", a);
}

请帮忙,反正这样做呢?*固件是2.2

Please help, anyway to do that? * The firmware is 2.2

推荐答案

使用以下

 context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

要查看是否有闪光灯可用。它会返回true或false。

to see if a flash is available or not. It will will return true or false.

这里更多关于如何真正落实code。

More here on how to actually implement the code.

的Andr​​oid LG革命手电筒

使用相机闪光灯在Android中

How在android系统只打开相机闪光灯编程?