How to turn on flashlight and front camera at the same time in android

前端 未结 3 1292
花落未央
花落未央 2020-12-11 21:22

In one of the requirement in my app I need to pop up an activity containing the front camera preview,at this same time I need to turn on the flashlight as well.However I obs

3条回答
  •  猫巷女王i
    2020-12-11 21:54

    Flashlight

     public void onToggleClicked(View view) {
        PackageManager pm = context.getPackageManager();
        final Parameters p = camera.getParameters();
        if (isFlashSupported(pm)) {
            boolean on = ((ToggleButton) view).isChecked();
            if (on) {
                Log.i("info", "torch is turn on!");
                p.setFlashMode(Parameters.FLASH_MODE_TORCH);
                camera.setParameters(p);
                camera.startPreview();
            } else {
                Log.i("info", "torch is turn off!");
                p.setFlashMode(Parameters.FLASH_MODE_OFF);
                camera.setParameters(p);
                camera.stopPreview();
            }
    

    Camera :

     ImageButton ib = (ImageButton) findViewById(R.id.buttonToast);
        ib.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(i, CAPTURE_IMAGE_CAPTURE_CODE);
            }
        });
    

提交回复
热议问题