Android zxing Embedded BarcodeView 未恢复 [英] Android zxing Embedded BarcodeView not resuming

查看:16

在我的 android 应用程序中,我使用了一个使用 BarcodeView 的 Fragment(CameraFragment 见下文).当条码被扫描 (BarcodeCallBack) 时,我会检查它是否符合某个模式,如果不符合,我想继续扫描,但这不起作用.相机继续运行但未扫描条码.作为快速修复,我替换了整个 Fragment,但这不是必须的.​​.....

片段:

package com.stickydata;导入 android.Manifest;导入 android.content.Context;导入 android.content.pm.PackageManager;导入 android.os.Build;导入 android.os.Bundle;导入 android.os.Vibrator;导入 android.support.annotation.NonNull;导入 android.support.v4.app.Fragment;导入 android.view.LayoutInflater;导入 android.view.View;导入 android.view.ViewGroup;导入 com.amazonaws.mobile.AWSMobileClient;导入 com.amazonaws.mobilehelper.auth.IdentityManager;导入 com.google.zxing.ResultPoint;导入 com.journeyapps.barcodescanner.BarcodeCallback;导入 com.journeyapps.barcodescanner.BarcodeResult;导入 com.journeyapps.barcodescanner.BarcodeView;导入 com.stickydata.AWSUtil.SDtagUtil;导入 com.stickydata.events.EventResumeBarcodeScan;导入 org.greenrobot.eventbus.EventBus;导入 java.util.List;导入静态 com.facebook.FacebookSdk.getApplicationContext;公共类 CameraFragment 扩展 Fragment {私有 IdentityManager 身份管理器;上下文 mcontext;私人 BarcodeView 条码视图;最终 int PERMISSIONS_REQUEST_ACCESS_CAMERA=0;查看视图;@覆盖公共视图 onCreateView(LayoutInflater inflater, ViewGroup 容器,捆绑savedInstanceState) {视图=inflater.inflate(R.layout.fragment_camera,容器,假);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&getActivity().checkSelfPermission(Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED) {请求权限(新字符串[]{Manifest.permission.CAMERA},PERMISSIONS_REQUEST_ACCESS_CAMERA);} 别的 {条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条码视图.decodeSingle(回调);}mcontext=getContext();返回视图;}@覆盖公共无效 onResume() {super.onResume();条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.resume();条码视图.decodeSingle(回调);}@覆盖公共无效 onPause() {super.onPause();条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.暂停();}私人 BarcodeCallback 回调 = 新 BarcodeCallback() {@覆盖公共无效barcodeResult(BarcodeResult结果){如果 (result.getText() != null) {条形码视图.暂停();//成功时的振动器振动器 v = (振动器) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);//振动 500 毫秒v. 振动(200);//在读取字符串后,我们对其进行处理字符串 tag_string=result.getText();AWSMobileClient.initializeMobileClientIfNecessary(getApplicationContext());//获取对移动客户端的引用.它是在 Application 类中创建的.最终 AWSMobileClient awsMobileClient = AWSMobileClient.defaultMobileClient();//获取对身份管理器的引用.identityManager = awsMobileClient.getIdentityManager();SDtagUtil sdTag=new SDtagUtil(tag_string,identityManager,awsMobileClient,mcontext);if(!sdTag.prozessTag()){//如果标签没有成功扫描让我们重新开始扫描EventBus.getDefault().post(new EventResumeBarcodeScan("bla"));//待办事项不工作//条形码视图.resume();//barcodeView.decodeSingle(回调);}}}@覆盖public void possibleResultPoints(List resultPoints) {}};@覆盖public void onRequestPermissionsResult(int requestCode, @NonNull String[] 权限, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);if (requestCode == PERMISSIONS_REQUEST_ACCESS_CAMERA|| grantResults!=null) {如果(grantResults[0] == PackageManager.PERMISSION_GRANTED){条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.decodeContinuous(回调);}}}}

片段xml文件

<com.journeyapps.barcodescanner.BarcodeViewandroid:id="@+id/barcode_scanner"android:layout_width="match_parent"android:layout_height="match_parent"应用程序:zxing_use_texture_view="true"应用程序:zxing_preview_scaling_strategy="fitCenter"/></LinearLayout>

按照建议更改为 decodeContinous.问题依旧:

package com.stickydata;导入 android.Manifest;导入 android.content.Context;导入 android.content.pm.PackageManager;导入 android.os.Build;导入 android.os.Bundle;导入 android.os.Vibrator;导入 android.support.annotation.NonNull;导入 android.support.v4.app.Fragment;导入 android.view.LayoutInflater;导入 android.view.View;导入 android.view.ViewGroup;导入 com.amazonaws.mobile.AWSMobileClient;导入 com.amazonaws.mobilehelper.auth.IdentityManager;导入 com.google.zxing.ResultPoint;导入 com.journeyapps.barcodescanner.BarcodeCallback;导入 com.journeyapps.barcodescanner.BarcodeResult;导入 com.journeyapps.barcodescanner.BarcodeView;导入 com.stickydata.AWSUtil.SDtagUtil;导入 com.stickydata.events.EventResumeBarcodeScan;导入 org.greenrobot.eventbus.EventBus;导入 java.util.List;导入静态 com.facebook.FacebookSdk.getApplicationContext;公共类 CameraFragment 扩展 Fragment {私有 IdentityManager 身份管理器;上下文 mcontext;私人 BarcodeView 条码视图;最终 int PERMISSIONS_REQUEST_ACCESS_CAMERA=0;查看视图;@覆盖公共视图 onCreateView(LayoutInflater inflater, ViewGroup 容器,捆绑savedInstanceState) {视图=inflater.inflate(R.layout.fragment_camera,容器,假);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&getActivity().checkSelfPermission(Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED) {请求权限(新字符串[]{Manifest.permission.CAMERA},PERMISSIONS_REQUEST_ACCESS_CAMERA);} 别的 {条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.decodeContinuous(回调);}mcontext=getContext();返回视图;}@覆盖公共无效 onResume() {super.onResume();条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.resume();条形码视图.decodeContinuous(回调);}@覆盖公共无效 onPause() {super.onPause();条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条码视图.暂停();}私人 BarcodeCallback 回调 = 新 BarcodeCallback() {@覆盖公共无效barcodeResult(BarcodeResult结果){如果 (result.getText() != null) {条形码视图.暂停();//成功时的振动器振动器 v = (振动器) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);//振动 500 毫秒v. 振动(200);//在读取字符串后,我们对其进行处理字符串 tag_string=result.getText();AWSMobileClient.initializeMobileClientIfNecessary(getApplicationContext());//获取对移动客户端的引用.它是在 Application 类中创建的.最终 AWSMobileClient awsMobileClient = AWSMobileClient.defaultMobileClient();//获取对身份管理器的引用.identityManager = awsMobileClient.getIdentityManager();SDtagUtil sdTag=new SDtagUtil(tag_string,identityManager,awsMobileClient,mcontext);if(!sdTag.prozessTag()){//如果标签没有成功扫描让我们重新开始扫描//EventBus.getDefault().post(new EventResumeBarcodeScan("bla"));//待办事项不工作条形码视图.resume();条形码视图.decodeContinuous(回调);}}}@覆盖public void possibleResultPoints(List resultPoints) {}};@覆盖public void onRequestPermissionsResult(int requestCode, @NonNull String[] 权限, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);if (requestCode == PERMISSIONS_REQUEST_ACCESS_CAMERA|| grantResults!=null) {如果(grantResults[0] == PackageManager.PERMISSION_GRANTED){条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.decodeContinuous(回调);}}}}
解决方案

嗨 user1406731 您使用了错误的回调,我们在我们的移动应用程序中做了类似的事情.用 decodeContinuous() 回调替换你的 decodeSingle() 回调函数,它应该可以工作.这是官方文档中的一个工作示例 连续回调示例.希望能帮到你.

嗨,我试图运行你的代码 &做了一点改变.这是我测试过的,对我来说很好

import android.Manifest;导入 android.content.Context;导入 android.content.pm.PackageManager;导入 android.os.Build;导入 android.os.Bundle;导入 android.support.annotation.NonNull;导入 android.util.Log;导入 android.view.LayoutInflater;导入 android.view.View;导入 android.view.ViewGroup;导入 com.google.zxing.ResultPoint;导入 com.journeyapps.barcodescanner.BarcodeCallback;导入 com.journeyapps.barcodescanner.BarcodeResult;导入 com.journeyapps.barcodescanner.BarcodeView;导入 com.example.scanner.R;导入 com.example.scanner.ui.base.BaseFragment;导入 java.util.List;/*** 由 Rishabh Bhatia 于 2017 年 12 月 5 日创建.*/公共类 CameraFragment 扩展 BaseFragment {上下文 mcontext;私人 BarcodeView 条码视图;最终 int PERMISSIONS_REQUEST_ACCESS_CAMERA=0;查看视图;@覆盖公共视图 onCreateView(LayoutInflater inflater, ViewGroup 容器,捆绑savedInstanceState) {视图=inflater.inflate(R.layout.fragment_camera,容器,假);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&getActivity().checkSelfPermission(Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED) {请求权限(新字符串[]{Manifest.permission.CAMERA},PERMISSIONS_REQUEST_ACCESS_CAMERA);} 别的 {条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.decodeContinuous(回调);}mcontext=getContext();返回视图;}@覆盖公共无效 onResume() {super.onResume();条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.resume();}@覆盖公共无效 onPause() {super.onPause();条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.暂停();}私人 BarcodeCallback 回调 = 新 BarcodeCallback() {@覆盖公共无效barcodeResult(BarcodeResult结果){如果 (result.getText() != null) {条形码视图.暂停();//在读取字符串后,我们对其进行处理字符串 tag_string=result.getText();Log.e("RISHABH", "暂停扫描仪,得到一些数据 "+tag_string);if(!tag_string.equals("abc")){//如果标签没有成功扫描让我们重新开始扫描Log.e("RISHABH", "正在恢复扫描,未找到所需数据");条形码视图.resume();//注意我们不再调用decodeContinuous函数}}}@覆盖public void possibleResultPoints(List resultPoints) {}};@覆盖public void onRequestPermissionsResult(int requestCode, @NonNull String[] 权限, @NonNull int[] grantResults) {super.onRequestPermissionsResult(requestCode, permissions, grantResults);如果(请求代码 == PERMISSIONS_REQUEST_ACCESS_CAMERA){如果(grantResults[0] == PackageManager.PERMISSION_GRANTED){条形码视图 = (BarcodeView) view.findViewById(R.id.barcode_scanner);条形码视图.decodeContinuous(回调);}}}}

这是我的日志

05-12 23:54:13.226 31403-31403/com.example.scanner E/RISHABH:暂停扫描,得到一些数据 ABC-abc-123405-12 23:54:13.226 31403-31403/com.example.scanner E/RISHABH:恢复扫描,未找到所需数据05-12 23:54:18.280 31403-31403/com.example.scanner E/RISHABH:暂停扫描仪,得到一些数据 ABC-abc-123405-12 23:54:18.280 31403-31403/com.example.scanner E/RISHABH:恢复扫描,未找到所需数据05-12 23:54:19.350 31403-31403/com.example.scanner E/RISHABH:暂停扫描仪,得到一些数据 ABC-abc-123405-12 23:54:19.350 31403-31403/com.example.scanner E/RISHABH:恢复扫描,未找到所需数据05-12 23:54:20.350 31403-31403/com.example.scanner E/RISHABH:暂停扫描仪,得到一些数据 ABC-abc-123405-12 23:54:20.350 31403-31403/com.example.scanner E/RISHABH:恢复扫描,未找到所需数据05-12 23:54:21.450 31403-31403/com.example.scanner E/RISHABH:暂停扫描仪,得到一些数据 ABC-abc-123405-12 23:54:21.450 31403-31403/com.example.scanner E/RISHABH:恢复扫描,未找到所需数据05-12 23:54:22.510 31403-31403/com.example.scanner E/RISHABH:暂停扫描仪,得到一些数据 ABC-abc-123405-12 23:54:22.510 31403-31403/com.example.scanner E/RISHABH:恢复扫描,未找到所需数据05-12 23:54:33.000 31403-31403/com.example.scanner E/RISHABH:暂停扫描仪,得到一些数据 abc
  • 原文

In my android app I use a Fragment (CameraFragment see below) which uses a BarcodeView. When a Barcode is scanned(BarcodeCallBack) I check if it fits a pattern and if not I want to resume the scanning, but this does not work. The camera keeps running but no Barcode is scanned. As a quickfix I replace the entire Fragment but this is not how it has to be...

The Fragment:

package com.stickydata;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.amazonaws.mobile.AWSMobileClient;
import com.amazonaws.mobilehelper.auth.IdentityManager;
import com.google.zxing.ResultPoint;
import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.BarcodeView;
import com.stickydata.AWSUtil.SDtagUtil;
import com.stickydata.events.EventResumeBarcodeScan;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import static com.facebook.FacebookSdk.getApplicationContext;

public class CameraFragment extends Fragment  {
    private IdentityManager identityManager;
Context mcontext;
    private BarcodeView barcodeView;
    final int PERMISSIONS_REQUEST_ACCESS_CAMERA=0;
    View view;


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

        view=inflater.inflate(R.layout.fragment_camera, container, false);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                getActivity().checkSelfPermission(Manifest.permission.CAMERA)
                        != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.CAMERA},
                    PERMISSIONS_REQUEST_ACCESS_CAMERA);
        } else {
            barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
            barcodeView.decodeSingle(callback);

        }


        mcontext=getContext();

        return view;
    }



    @Override
    public void onResume() {

        super.onResume();
        barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
        barcodeView.resume();
        barcodeView.decodeSingle(callback);

    }

    @Override
    public void onPause() {
        super.onPause();
        barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
        barcodeView.pause();
    }


    private BarcodeCallback callback = new BarcodeCallback() {
        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                barcodeView.pause();
                //the vibrator on success
                Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
               // Vibrate for 500 milliseconds
                v.vibrate(200);
               //after the string has been read we prozess it
                String tag_string=result.getText();
                AWSMobileClient.initializeMobileClientIfNecessary(getApplicationContext());
                // Obtain a reference to the mobile client. It is created in the Application class.
                final AWSMobileClient awsMobileClient = AWSMobileClient.defaultMobileClient();

                // Obtain a reference to the identity manager.
                identityManager = awsMobileClient.getIdentityManager();
                SDtagUtil sdTag=new SDtagUtil(tag_string,identityManager,awsMobileClient,mcontext);

                if(!sdTag.prozessTag()){//if the tag was not scanned succesfully let us start the scan again
                    EventBus.getDefault().post(new EventResumeBarcodeScan("bla"));
                    //TODO NOT WORKING
                  //  barcodeView.resume();
                  //  barcodeView.decodeSingle(callback);

                }


            }


        }

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

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == PERMISSIONS_REQUEST_ACCESS_CAMERA|| grantResults!=null) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
                barcodeView.decodeContinuous(callback);
            }
        }
    }
}

The fragment xml file

<?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"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.journeyapps.barcodescanner.BarcodeView
        android:id="@+id/barcode_scanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:zxing_use_texture_view="true"
    app:zxing_preview_scaling_strategy="fitCenter"/>
</LinearLayout>

Changed to decodeContinous as suggested. The problem remains:

package com.stickydata;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.amazonaws.mobile.AWSMobileClient;
import com.amazonaws.mobilehelper.auth.IdentityManager;
import com.google.zxing.ResultPoint;
import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.BarcodeView;
import com.stickydata.AWSUtil.SDtagUtil;
import com.stickydata.events.EventResumeBarcodeScan;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import static com.facebook.FacebookSdk.getApplicationContext;

public class CameraFragment extends Fragment  {
    private IdentityManager identityManager;
Context mcontext;
    private BarcodeView barcodeView;
    final int PERMISSIONS_REQUEST_ACCESS_CAMERA=0;
    View view;


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

        view=inflater.inflate(R.layout.fragment_camera, container, false);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                getActivity().checkSelfPermission(Manifest.permission.CAMERA)
                        != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.CAMERA},
                    PERMISSIONS_REQUEST_ACCESS_CAMERA);
        } else {
            barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
            barcodeView.decodeContinuous(callback);

        }


        mcontext=getContext();

        return view;
    }



    @Override
    public void onResume() {

        super.onResume();
        barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
        barcodeView.resume();
        barcodeView.decodeContinuous(callback);

    }

    @Override
    public void onPause() {
        super.onPause();
        barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
        barcodeView.pause();
    }


    private BarcodeCallback callback = new BarcodeCallback() {
        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                barcodeView.pause();
                //the vibrator on success
                Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
               // Vibrate for 500 milliseconds
                v.vibrate(200);
               //after the string has been read we prozess it
                String tag_string=result.getText();
                AWSMobileClient.initializeMobileClientIfNecessary(getApplicationContext());
                // Obtain a reference to the mobile client. It is created in the Application class.
                final AWSMobileClient awsMobileClient = AWSMobileClient.defaultMobileClient();

                // Obtain a reference to the identity manager.
                identityManager = awsMobileClient.getIdentityManager();
                SDtagUtil sdTag=new SDtagUtil(tag_string,identityManager,awsMobileClient,mcontext);

                if(!sdTag.prozessTag()){//if the tag was not scanned succesfully let us start the scan again
                   // EventBus.getDefault().post(new EventResumeBarcodeScan("bla"));
                    //TODO NOT WORKING
                    barcodeView.resume();
                    barcodeView.decodeContinuous(callback);

                }


            }


        }

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

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == PERMISSIONS_REQUEST_ACCESS_CAMERA|| grantResults!=null) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
                barcodeView.decodeContinuous(callback);
            }
        }
    }
}
解决方案

Hi user1406731 you are using the wrong callback, we do something similar in our mobile app. Replace your decodeSingle() callback function with decodeContinuous() callback and it should work. Here is a working example from the official doc Continous Callback example. Hope it helps you.

Hi i tried to run your code & made a little change. This is what i tested and works fine for me

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.zxing.ResultPoint;
import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.BarcodeView;
import com.example.scanner.R;
import com.example.scanner.ui.base.BaseFragment;

import java.util.List;

/**
 * Created by Rishabh Bhatia on 12/5/17.
 */

public class CameraFragment extends BaseFragment {
    Context mcontext;
    private BarcodeView barcodeView;
    final int PERMISSIONS_REQUEST_ACCESS_CAMERA=0;
    View view;


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

        view=inflater.inflate(R.layout.fragment_camera, container, false);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                getActivity().checkSelfPermission(Manifest.permission.CAMERA)
                        != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.CAMERA},
                    PERMISSIONS_REQUEST_ACCESS_CAMERA);
        } else {
            barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
            barcodeView.decodeContinuous(callback);

        }


        mcontext=getContext();

        return view;
    }



    @Override
    public void onResume() {

        super.onResume();
        barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
        barcodeView.resume();    
    }

    @Override
    public void onPause() {
        super.onPause();
        barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
        barcodeView.pause();
    }

    private BarcodeCallback callback = new BarcodeCallback() {
        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                barcodeView.pause();
                //after the string has been read we prozess it
                String tag_string=result.getText();
                Log.e("RISHABH", "pausing scanner, got some data "+tag_string);

                if(!tag_string.equals("abc")){//if the tag was not scanned succesfully let us start the scan again
                    Log.e("RISHABH", "resuming scanner, data needed was not found");
                    barcodeView.resume(); //notice we don't call decodeContinuous function again
                }
            }
        }

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

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == PERMISSIONS_REQUEST_ACCESS_CAMERA) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                barcodeView = (BarcodeView) view.findViewById(R.id.barcode_scanner);
                barcodeView.decodeContinuous(callback);
            }
        }
    }
}

Here is my logcat

05-12 23:54:13.226 31403-31403/com.example.scanner E/RISHABH: pausing scanner, got some data ABC-abc-1234
05-12 23:54:13.226 31403-31403/com.example.scanner E/RISHABH: resuming scanner, data needed was not found
05-12 23:54:18.280 31403-31403/com.example.scanner E/RISHABH: pausing scanner, got some data ABC-abc-1234
05-12 23:54:18.280 31403-31403/com.example.scanner E/RISHABH: resuming scanner, data needed was not found
05-12 23:54:19.350 31403-31403/com.example.scanner E/RISHABH: pausing scanner, got some data ABC-abc-1234
05-12 23:54:19.350 31403-31403/com.example.scanner E/RISHABH: resuming scanner, data needed was not found
05-12 23:54:20.350 31403-31403/com.example.scanner E/RISHABH: pausing scanner, got some data ABC-abc-1234
05-12 23:54:20.350 31403-31403/com.example.scanner E/RISHABH: resuming scanner, data needed was not found
05-12 23:54:21.450 31403-31403/com.example.scanner E/RISHABH: pausing scanner, got some data ABC-abc-1234
05-12 23:54:21.450 31403-31403/com.example.scanner E/RISHABH: resuming scanner, data needed was not found
05-12 23:54:22.510 31403-31403/com.example.scanner E/RISHABH: pausing scanner, got some data ABC-abc-1234
05-12 23:54:22.510 31403-31403/com.example.scanner E/RISHABH: resuming scanner, data needed was not found
05-12 23:54:33.000 31403-31403/com.example.scanner E/RISHABH: pausing scanner, got some data abc