dlazaro66 / QRCodeReaderView

Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
1.9k stars 491 forks source link

Flashlight is not detected or there is no option to change front camera or back #98

Open Tufan21 opened 7 years ago

Tufan21 commented 7 years ago

hii sir i am using these in fragment ..already enabled these feature but it is not working

i am using these version compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.1'

    mydecoderview = (QRCodeReaderView)rootView. findViewById(R.id.qrdecoderview);
    mydecoderview.setOnQRCodeReadListener(this);

 // Use this function to enable/disable decoding
    mydecoderview.setQRDecodingEnabled(true);

    // Use this function to change the autofocus interval (default is 5 secs)
    mydecoderview.setAutofocusInterval(2000L);

    // Use this function to enable/disable Torch
    mydecoderview.setTorchEnabled(true);

    // Use this function to set front camera preview
    mydecoderview.setFrontCamera();

    // Use this function to set back camera preview
    mydecoderview.setBackCamera();
dlazaro66 commented 7 years ago

Sorry, I don't catch your question, can you explain me again what's happening/not working?

seyidkanan commented 6 years ago

Hi, I cannot enabled torch. My code simple:

MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.dlazaro66.qrcodereaderview.QRCodeReaderView;

public class MainActivity extends AppCompatActivity implements QRCodeReaderView.OnQRCodeReadListener {

    private QRCodeReaderView qrCodeReaderView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
        qrCodeReaderView.setOnQRCodeReadListener(this);

        // Use this function to enable/disable decoding
        qrCodeReaderView.setQRDecodingEnabled(true);

        // Use this function to change the autofocus interval (default is 5 secs)
        qrCodeReaderView.setAutofocusInterval(2000L);

        // Use this function to enable/disable Torch
        qrCodeReaderView.setTorchEnabled(true);

        // Use this function to set front camera preview
//        qrCodeReaderView.setFrontCamera();

        // Use this function to set back camera preview
        qrCodeReaderView.setBackCamera();
    }

    @Override
    public void onQRCodeRead(String text, PointF[] points) {
        Log.e("kanan", text);
    }

    @Override
    protected void onResume() {
        super.onResume();
        qrCodeReaderView.startCamera();
    }

    @Override
    protected void onPause() {
        super.onPause();
        qrCodeReaderView.stopCamera();
    }

}

And activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.dlazaro66.qrcodereaderview.QRCodeReaderView
        android:id="@+id/qrdecoderview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

And when I use debug CameraManager in package com.google.zxing.client.android.camera; call this function and debug result is theCamera: null, enabled: true:

public synchronized void setTorchEnabled(boolean enabled) {
    OpenCamera theCamera = openCamera;
    if (theCamera != null && enabled != configManager.getTorchState(theCamera.getCamera())) { 
      boolean wasAutoFocusManager = autoFocusManager != null;
      if (wasAutoFocusManager) {
        autoFocusManager.stop();
        autoFocusManager = null;
      }
      configManager.setTorchEnabled(theCamera.getCamera(), enabled);
      if (wasAutoFocusManager) {
        autoFocusManager = new AutoFocusManager(theCamera.getCamera());
        autoFocusManager.start();
      }
    }
  }