How can I use scan QR Code with a camera inside the layout (like Whatsapp Web scanner)

Renato Gonçalves

I'm developer but new in Android and I need to know how can I use camera inside a Activity Layout.

I know I need to use Surface View to insert camera inside an activity and currently my app is reading QR Codes with Google Vision using default camera (a button opens camera, the user takes the photo and my app perceive the activity result).

But I really need to implementation that function inside app with real-time scanner.

Someone can direct me?

Sanket Mendon

Here is how I implemented something similar to what you need.

-Firstly, I used the Zxing library to implement this. So you need to add below dependency to your gradle:

compile 'com.journeyapps:zxing-android-embedded:3.5.0'

-Below is a direct link to the journeyapps scanner projects' Github link:

https://github.com/journeyapps/zxing-android-embedded

-Below is how I made my layout file:

<!-- language: lang-xml -->
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.journeyapps.barcodescanner.DecoratedBarcodeView
        android:id="@+id/view_scanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/view_footer"
        android:soundEffectsEnabled="true" />

    <LinearLayout
        android:id="@+id/view_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/view_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center|top"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/_10sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:src="@drawable/ic_back_light" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/_50sdp"
            android:gravity="right|top">

            <ImageView
                android:id="@+id/iv_flash"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/_10sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:src="@drawable/ic_flash_inactive" />
        </LinearLayout>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/view_footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:gravity="center"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="@dimen/_10sdp"
            android:layout_marginRight="@dimen/_10sdp"
            android:background="@android:color/darker_gray" />

        <TextView
            android:id="@+id/code_info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@string/font_sans_serif_light"
            android:padding="@dimen/_15sdp"
            android:text="@string/app_name"
            android:textColor="@android:color/white"
            android:textSize="@dimen/_15sdp" />


    </LinearLayout>

</FrameLayout>

So now the DecoratedBarcodeView serves as your main scanning area within your layout.

-Initialize your barcode view as below:

private DecoratedBarcodeView barcodeView;

barcodeView = (DecoratedBarcodeView) findViewById(R.id.view_scanner);
barcodeView.setStatusText("");
barcodeView.decodeContinuous(callback);

-In your activity, you can fetch the Scan result in your BarcodeCallback in this way:

private BarcodeCallback callback = new BarcodeCallback() {
    @Override
    public void barcodeResult(BarcodeResult result) {
        //Process your scan result here
        String resultString = result.getText();
    }

    @Override
    public void possibleResultPoints(List<ResultPoint> resultPoints) {
    }
};

Hope this helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can i scan the bar code and qr code via mobile camera?

From Dev

How can I use WhatsApp Web on Ubuntu?

From Dev

Android I use Zxing Qr code, how to scan local Qr code image?

From Dev

How can I use a scanner library and scan in the background of the my android app using an embedded scanner?

From Dev

How to make a counter inside my tab layout like Whatsapp?

From Dev

How do I use the metadataOutputRectOfInterestForRect method and rectOfInterest property to scan a specific area? (QR Code)

From Dev

How can I securely transmit a unique customer QR code to business scanner?

From Dev

Can I use Windows Fax and Scan with a ScanSnap scanner?

From Dev

How can you use VIP Scanner to scan and test plugins

From Dev

barcode scanner intent launches but cannot scan qr code?

From Java

Possibilities to scan qr-code in flutter web

From Dev

Scan the QR code picture directly from camera with ZXing

From Dev

How can i download images like Whatsapp from cloud storage

From Dev

How can I use a scanner in .NET?

From Dev

How can I create layout like this?

From Dev

Android Studio Zxing Scanner, how to redirect to web page if result from QR code is URL

From Dev

What to do with a QR code from web.whatsapp.com?

From Dev

How can i use Symfony or Zend Components inside Code Igniter?

From Dev

How can i use Symfony or Zend Components inside Code Igniter?

From Dev

How do I get a QR code to from my telerik app-builder project so that I can scan it and preview the application from my device?

From Dev

Animation with scan QR code

From Dev

Can I use the scanner driver to scan directly to a file instead of importing into a program?

From Dev

How do I create a QR code scanner that goes to a particular screen in my app

From Dev

How do I get the Huawei App Linking work with QR code scan?

From Dev

How can I use front camera and back camera simultaneously on the iPhone

From Dev

Use Google Glass Mirror API to scan QR code

From Dev

How can I use the WhatsApp Share Button to share Images?

From Dev

ZXing QR code scanner embedded pressing back button during scan issue

From Dev

How can I create QR code from MySQL data?

Related Related

  1. 1

    How can i scan the bar code and qr code via mobile camera?

  2. 2

    How can I use WhatsApp Web on Ubuntu?

  3. 3

    Android I use Zxing Qr code, how to scan local Qr code image?

  4. 4

    How can I use a scanner library and scan in the background of the my android app using an embedded scanner?

  5. 5

    How to make a counter inside my tab layout like Whatsapp?

  6. 6

    How do I use the metadataOutputRectOfInterestForRect method and rectOfInterest property to scan a specific area? (QR Code)

  7. 7

    How can I securely transmit a unique customer QR code to business scanner?

  8. 8

    Can I use Windows Fax and Scan with a ScanSnap scanner?

  9. 9

    How can you use VIP Scanner to scan and test plugins

  10. 10

    barcode scanner intent launches but cannot scan qr code?

  11. 11

    Possibilities to scan qr-code in flutter web

  12. 12

    Scan the QR code picture directly from camera with ZXing

  13. 13

    How can i download images like Whatsapp from cloud storage

  14. 14

    How can I use a scanner in .NET?

  15. 15

    How can I create layout like this?

  16. 16

    Android Studio Zxing Scanner, how to redirect to web page if result from QR code is URL

  17. 17

    What to do with a QR code from web.whatsapp.com?

  18. 18

    How can i use Symfony or Zend Components inside Code Igniter?

  19. 19

    How can i use Symfony or Zend Components inside Code Igniter?

  20. 20

    How do I get a QR code to from my telerik app-builder project so that I can scan it and preview the application from my device?

  21. 21

    Animation with scan QR code

  22. 22

    Can I use the scanner driver to scan directly to a file instead of importing into a program?

  23. 23

    How do I create a QR code scanner that goes to a particular screen in my app

  24. 24

    How do I get the Huawei App Linking work with QR code scan?

  25. 25

    How can I use front camera and back camera simultaneously on the iPhone

  26. 26

    Use Google Glass Mirror API to scan QR code

  27. 27

    How can I use the WhatsApp Share Button to share Images?

  28. 28

    ZXing QR code scanner embedded pressing back button during scan issue

  29. 29

    How can I create QR code from MySQL data?

HotTag

Archive