clover-faq avatar image
clover-faq asked morenoh149 commented

How do I programmatically use the camera barcode scanner on the Mobile?

I have an app that utilizes the Barcode Scanner camera on Mini and Station. How do I get the same functionality on a Mobile device?
Clover Mobilebarcode scanner
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

clover-faq avatar image
clover-faq answered morenoh149 commented
Given the below code sample, we're able to utilize the scanner on all Clover devices. The difference between the Mini/Station and the Mobile is that Mini/Station uses the camera and the Mobile has a separate built in barcode scanner. With this code, a button within your app can be pushed so the preview window for scanning will pop up on the Mini and Station or a red light will appear out of the side of the Mobile (both indicating that you may begin scanning items).

There is not a direct way to use the camera on a Mobile for scanning, but it may be possible through the use of third party libraries.

Code Sample:
import android.os.Bundle;
import android.content.BroadcastReceiver;
import android.widget.Button;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.TextView;
import android.view.View;

import com.clover.sdk.v1.Intents;
import com.clover.sdk.v3.scanner.BarcodeScanner;
import com.clover.sdk.v3.scanner.BarcodeResult;

public class MainActivity extends Activity {

    private Button mBarcodeOnButton;
    private Button mBarcodeOffButton;
    private BarcodeScanner mBarcodeScanner;
    private TextView barcode_result;

    private BroadcastReceiver barcodeReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            BarcodeResult barcodeResult = new BarcodeResult(intent);

            if (barcodeResult.isBarcodeAction()) {
                String barcode = barcodeResult.getBarcode();
                barcode_result.setText("Result: " + barcode);

    protected void onCreate(Bundle savedInstanceState) {
        mBarcodeScanner = new BarcodeScanner(this);

    protected void onResume() {
        barcode_result = (TextView) findViewById(;

        mBarcodeOnButton = (Button) findViewById(;
        mBarcodeOnButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Bundle extras = new Bundle();
                extras.putBoolean(Intents.EXTRA_SCAN_QR_CODE, true); # Checks for QR codes
                extras.putBoolean(Intents.EXTRA_SCAN_1D_CODE, true); # Checks for a standard barcode

        mBarcodeOffButton = (Button) findViewById(;
        mBarcodeOffButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

    protected void onPause() {

    private void registerBarcodeScanner() {
        registerReceiver(barcodeReceiver, new IntentFilter(BarcodeResult.INTENT_ACTION));

    private void unregisterBarcodeScanner() {
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

morenoh149 avatar image morenoh149 commented ·

This code seems to depend on some accompanying layout file. I get

error: cannot find symbol variable activity_main

and other errors when accessing `R.layout` or ``. Could you share some accompanying layout file?

1 Like 1 ·
morenoh149 avatar image morenoh149 morenoh149 commented ·

Seems like the example has changed over time. The current version is at and has the accompanying layout resources.

1 Like 1 ·

Welcome to the
Clover Developer Community