w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to turn on flashlight and front camera at the same time in android

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);
        }
    });




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.