# Print output for @column tags ?> ScannerFragment | Android Developers

Most visited

Recently visited

ScannerFragment

public class ScannerFragment
extends Fragment implements TextureView.SurfaceTextureListener

java.lang.Object
   ↳ android.app.Fragment
     ↳ com.vuzix.sdk.barcode.ScannerFragment


ScannerFragment is an easy way to add barcode scanning functionality to your app. To use, follow these steps:

  1. Obtain CAMERA permissions. ScannerFragment makes no attempt to request permissions on its own. Failure to obtain CAMERA permissions will cause scanning to fail.
  2. Instantiate an instance of ScannerFragment.
  3. Register a listener to receive barcode scanning results.
  4. Use FragmentManager to add the fragment to your activity. For best results, add fragment should be added within a 16x9 container.

Summary

Nested classes

interface ScannerFragment.Listener

Interface for those who want to be notified when a barcode is identified. 

interface ScannerFragment.Listener2

 

Constants

String ARG_BARCODE2_TYPES

A string array argument for specifying barcode types to scan for.

String ARG_BARCODE_TYPES

This constant is deprecated. As of Scanner 2

String ARG_CAMERA_ID

A String argument for specifying the desired camera to use

arguments.putString(ScannerFragment.ARG_CAMERA_ID, 1);

String ARG_LICENSE_KEY

This constant is deprecated. As of Scanner 2

String ARG_SCANNING_RECT

A parcelable argument for specifying the scanning rect.

String ARG_ZOOM_IN_MODE

A boolean argument for barcode run in zoom mode.

Public constructors

ScannerFragment()

Public methods

void onCreate(Bundle savedInstanceState)
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void onStart()
void onStop()
void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
boolean onSurfaceTextureDestroyed(SurfaceTexture surface)
void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)
void onSurfaceTextureUpdated(SurfaceTexture surface)
void setListener(ScannerFragment.Listener listener)

This method is deprecated. As of Scanner 2

void setListener2(ScannerFragment.Listener2 listener)

Register a callback to be invoked when a barcode is located or an error occurs.

Constants

ARG_BARCODE2_TYPES

public static final String ARG_BARCODE2_TYPES

A string array argument for specifying barcode types to scan for. Each string should be the name() of a BarcodeType2. For example:

arguments.putStringArray(ScannerFragment.ARG_BARCODE2_TYPES, new String[] {BarcodeType2.QR.name(), BarcodeType2.QR_MICRO.name()});

Constant Value: "barcode2_types"

ARG_BARCODE_TYPES

public static final String ARG_BARCODE_TYPES

This constant is deprecated.
As of Scanner 2

A string array argument for specifying barcode types to scan for. Each string should be the name() of a BarcodeType. For example:

arguments.putStringArray(ScannerFragment.ARG_BARCODE_TYPES, new String[] {BarcodeType.QR.name(), BarcodeType.QR_MICRO.name()});

Constant Value: "barcode_types"

ARG_CAMERA_ID

public static final String ARG_CAMERA_ID

A String argument for specifying the desired camera to use

arguments.putString(ScannerFragment.ARG_CAMERA_ID, 1);

Constant Value: "camera_id"

ARG_LICENSE_KEY

public static final String ARG_LICENSE_KEY

This constant is deprecated.
As of Scanner 2

A string argument for specifying a custom license key.

Constant Value: "license_key"

ARG_SCANNING_RECT

public static final String ARG_SCANNING_RECT

A parcelable argument for specifying the scanning rect. For example:

arguments.putParcelable(ScannerFragment.ARG_SCANNING_RECT, new ScanningRect(.5f, .5f));

Constant Value: "scanning_rect"

ARG_ZOOM_IN_MODE

public static final String ARG_ZOOM_IN_MODE

A boolean argument for barcode run in zoom mode. For example:

arguments.putBoolean(ScannerFragment.ARG_ZOOM_MODE, true);

Constant Value: "zoom_in_mode"

Public constructors

ScannerFragment

public ScannerFragment ()

Public methods

onCreate

public void onCreate (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onCreateView

public View onCreateView (LayoutInflater inflater, 
                ViewGroup container, 
                Bundle savedInstanceState)

Parameters
inflater LayoutInflater

container ViewGroup

savedInstanceState Bundle

Returns
View

onStart

public void onStart ()

onStop

public void onStop ()

onSurfaceTextureAvailable

public void onSurfaceTextureAvailable (SurfaceTexture surface, 
                int width, 
                int height)

Parameters
surface SurfaceTexture

width int

height int

onSurfaceTextureDestroyed

public boolean onSurfaceTextureDestroyed (SurfaceTexture surface)

Parameters
surface SurfaceTexture

Returns
boolean

onSurfaceTextureSizeChanged

public void onSurfaceTextureSizeChanged (SurfaceTexture surface, 
                int width, 
                int height)

Parameters
surface SurfaceTexture

width int

height int

onSurfaceTextureUpdated

public void onSurfaceTextureUpdated (SurfaceTexture surface)

Parameters
surface SurfaceTexture

setListener

public void setListener (ScannerFragment.Listener listener)

This method is deprecated.
As of Scanner 2

Register a callback to be invoked when a barcode is located or an error occurs. To remove yourself as a listener, set the listener to null.

Parameters
listener ScannerFragment.Listener: a ScannerFragment.Listener

setListener2

public void setListener2 (ScannerFragment.Listener2 listener)

Register a callback to be invoked when a barcode is located or an error occurs. To remove yourself as a listener, set the listener to null.

Parameters
listener ScannerFragment.Listener2: a ScannerFragment.Listener2