Giter VIP home page Giter VIP logo

Comments (6)

freebumba27 avatar freebumba27 commented on August 20, 2024

Still now no solution? :-(

from mobilevisionbarcodescanner.

KingsMentor avatar KingsMentor commented on August 20, 2024

@Bekakk Make sure you can camera permission granted for marshmallow devices. This should work.

from mobilevisionbarcodescanner.

freebumba27 avatar freebumba27 commented on August 20, 2024

@KingsMentor Even I grant it first time it does not work.

if(!hasPermissions(getContext(), PERMISSIONS)) {
ActivityCompat.requestPermissions(getActivity(), PERMISSIONS, CAMERA_PERMISSION_REQUEST_CODE);
} else {
barcodeCapture = (BarcodeCapture) getChildFragmentManager().findFragmentById(barcode);
barcodeCapture.setRetrieval(this);
}

from mobilevisionbarcodescanner.

KingsMentor avatar KingsMentor commented on August 20, 2024

@freebumba27 . Thanks for pointing this out. The problem is the xml has already been inflated and if the permission has not been granted, the app wouldn't be able to use the camera. Here is a quick fix:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_blur_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/mainLayout"
        layout="@layout/toolbar" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/mainLayout"
        android:background="#000"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingTop="50dp">

        <LinearLayout
            android:id="@+id/cam_layout"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:orientation="vertical"/>


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="16dp"
            android:text="Align the QR Code/bar code within the frame to scan"
            android:textColor="#fff" />

    </LinearLayout>

</RelativeLayout>

Notice that the barcode fragment in not in this xml.
I moved it to a seperated xml file : cam_layout.xml and inflate it only when the permission has been granted.

Achieved that with this snippet:

View camView = LayoutInflater.from(this).inflate(R.layout.cam_layout, null, false);
                ((LinearLayout) findViewById(R.id.cam_layout)).addView(camView);
                barcodeCapture = (BarcodeCapture) getSupportFragmentManager().findFragmentById(R.id.barcode);
                barcodeCapture.setRetrieval(this);

and here is cam_layout.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/barcode"
    android:name="com.google.android.gms.samples.vision.barcodereader.BarcodeCapture"
    android:layout_width="300dp"
    android:layout_height="300dp"
    app:gvb_auto_focus="true"
    app:gvb_code_format="all_format"
    app:gvb_flash="false" />

A more usable update will be pushed but this should work for you.

from mobilevisionbarcodescanner.

KingsMentor avatar KingsMentor commented on August 20, 2024

@freebumba27 does this works for you ?

from mobilevisionbarcodescanner.

freebumba27 avatar freebumba27 commented on August 20, 2024

Yes it worked perfectly. I will suggest you to make the camera full screen. I have tested the app in S7 edge it's taking back area at the bottom of the screen. I think it's duo to resolution. If you can fix this part and update the dependency then this one of the best Lib based on MobileVison

from mobilevisionbarcodescanner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.