ZXing条码扫描器采用片段2中的自定义布局

时间:2016-09-15 10:29:02

标签: android zxing barcode-scanner

Using ZXing Android Embedded

Example taken from here and there is the answer

我的片段类:

    $scope.signupForm={};//user object
    $scope.beginSignUp=function(){
     //sign up 

      var details = {
        'email': $scope.signupForm.email,
        'password': $scope.signupForm.pass,
        'details':{
          'name':$scope.signupForm.dn,
          'image':$scope.signupForm.dp
        }
      } 

      Ionic.Auth.signup(details).then(signupSuccess, function(err){

      });
    }

    $scope.signupSuccess=function(){

        console.log("ionic sign up sucess, now login the user");
        var authProvider = 'basic';
        var authSettings = { 'remember': true };
        var loginDetails = {
          'email': $scope.signupForm.email,
          'password': $scope.signupForm.pass
        };

        Ionic.Auth.login(authProvider, authSettings, loginDetails)
        .then(authSuccess, function(err){


        });
    }

    function authSuccess(){

        console.log("Ionic Login Success ");
        var ionic_user = Ionic.User.current();
        ionic_user.details.name =$scope.signupForm.dn;
        ionic_user.details.image = $scope.signupForm.dp;
        ionic_user.save();


        registerPush();


        $ionicHistory.nextViewOptions({
              disableBack: true
        });

        $state.go('home', {}, {reload: true});
    }

function registerPush(){
   console.log("Calling Register Push");
   $ionicPush.init({
    "debug": true,
    "onNotification": function(notification) {
      var payload = notification.payload;
      console.log(notification, payload);
    },
    "onRegister": function(data) {
      console.log(data.token);
      Ionic.User.current();
      $ionicPush.saveToken(data.token);
      //unregister after checking

    },
    "pluginConfig": {
      "ios": {
        "badge": true,
        "sound": true
      },
      "android": {
         "iconColor": "#FA2B2E",
         "senderID": "GCM Project No.",
         "icon":"notification"
      }  
    } 
  });
  $ionicPush.register();
}

片段xml:

    public class ExciseBarcodeScanFragment extends AbstractFragment {
    private Button button;
    private CompoundBarcodeView barcodeView;

    @Override
    public int getTitleRes() {
        return R.string.validation_of_excise_stamps_on_alcohol_products;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_excise_barcode_scan, container, false);
        init(rootView);

        return rootView;
    }

    private void init(View rootView) {
        // ...

        barcodeView = (CompoundBarcodeView) rootView.findViewById(R.id.barcode_scanner);
        barcodeView.decodeContinuous(callback);
    }

    private BarcodeCallback callback = new BarcodeCallback() {
        @Override
        public void barcodeResult(BarcodeResult result) {
            if (result.getText() != null) {
                barcodeView.setStatusText(result.getText());
            }

            //Do something with code result
        }

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

    @Override
    public void onResume() {
        barcodeView.resume();
        super.onResume();
    }

    @Override
    public void onPause() {
        barcodeView.pause();
        super.onPause();
    }
}

Screen

我知道这是重复的,但它不起作用。 我很新,如果可怕的格式化,我很抱歉。 请帮忙。

1 个答案:

答案 0 :(得分:0)

一切正常。它打开模拟器,如图所示似乎不起作用,并在您的手机上工作。