3

I've a Barcode Scanner app that using (Barcode Detection with the Google Mobile Vision API) in camera activity i want to set a frame so the app just read barcodes or QRcodes which is in that frame (like all scanner apps) how can i customize it?

here is camera xml layout:

<?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"
    android:orientation="vertical"
    tools:context=".ScanBarcodeActivity">

    <SurfaceView
        android:id="@+id/cammeraPreview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
A.R.B.N
  • 1,035
  • 2
  • 10
  • 20

1 Answers1

0

This being a barcode scanner and not a generic camera preview does not change a lot. You can follow this answer to add a rectangle 'above' the preview surface. Note that this implies that the top-level layout of your Activity is FrameLayout.

You could try to check the coordinates of the recognized barcode and ignore it if they don't match the rectangle you draw, but IMO this would be a waste of time – both for you and for the end user. This will not add to reliability of recognition.

On the other hand, a visual guide (your custom frame) does improve barcode scanner UX even if there is no programmatic logic behind it.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307