闪光灯光线越来越开关,同时改变方向关闭闪光灯、光线、方向

2023-09-08 09:36:02 作者:緈茗菛·缺

我已经创建了一个Android应用程序,这将允许用户打开和pressing一键关闭闪光灯。如果闪存光用户交换机和更改方向,光被越来越关闭。为什么发生这种情况。请参阅code以下,我使用的。

 凸轮= Camera.open();
    最终的参数P = cam.getParameters();

    torch_switch =(按钮)findViewById(R.id.torch_switch);
    torch_switch.setOnClickListener(新OnClickListener(){

        公共无效的onClick(视图v){


            // TODO自动生成方法存根
            如果(isLightOn){
                torch_switch.setText(开启火炬);
                p.setFlashMode(Parameters.FLASH_MODE_OFF);
                cam.setParameters(对);
                cam.stop preVIEW();
                isLightOn = FALSE;

            } 其他 {
                torch_switch.setText(开关关闭火炬);
                p.setFlashMode(Parameters.FLASH_MODE_TORCH);
                cam.setParameters(对);
                cam.start preVIEW();
                isLightOn = TRUE;
            }
        }
    });
 

解决方案

更​​改方向会导致您的应用程序,以破坏其目前的活动,然后重新创建它,实际上从一开始就再次启动应用程序。

您可以修复它​​通过禁止在清单方向的变化,或将当前的模式,你的的onStop方法,然后恢复它的OnStart,可能是。

可反射闪光拍摄 便携闪光灯尼康SB300发布

I have created an android app which will allow the user to switch on and switch off the flash light by pressing a button. If the user switch on the flash light and change the orientation, the light is getting switched off. Why this is happening. Please see the code below which i used.

cam = Camera.open();
    final Parameters p = cam.getParameters();

    torch_switch = (Button)findViewById(R.id.torch_switch);
    torch_switch.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {


            // TODO Auto-generated method stub
            if(isLightOn) {
                torch_switch.setText("Switch ON Torch");
                p.setFlashMode(Parameters.FLASH_MODE_OFF);
                cam.setParameters(p);
                cam.stopPreview();
                isLightOn = false;

            } else {
                torch_switch.setText("Switch OFF Torch");
                p.setFlashMode(Parameters.FLASH_MODE_TORCH);
                cam.setParameters(p);
                cam.startPreview();
                isLightOn = true;
            }
        }
    });

解决方案

Changing orientation causes your app to destroy its current activity and then recreate it, essentially starting the app again from the start.

You could fix it by disallowing orientation changes in the manifest, or store the current mode in your 'onStop' method and then restoring it in 'OnStart', possibly.