package com.mahimahistudio.barcodereader;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;

import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.BeepManager;
import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.DecoratedBarcodeView;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String LOG_TAG = MainActivity.class.getSimpleName();
    private DecoratedBarcodeView barcodeView;
    private BeepManager beepManager;
    private String lastText;

    private BarcodeCallback callback = new BarcodeCallback() {
        @Override
        public void barcodeResult(BarcodeResult result) {
            if(result.getText() == null || result.getText().equals(lastText)) {
                // Prevent duplicate scans
                return;
            }

            lastText = result.getText();
            barcodeView.setStatusText(result.getText());
            beepManager.playBeepSoundAndVibrate();
        }

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


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner);
        barcodeView.decodeContinuous(callback);
        beepManager = new BeepManager(this);


    }

    @Override
    protected void onResume() {
        super.onResume();

        barcodeView.resume();
    }

    @Override
    protected void onPause() {
        super.onPause();

        barcodeView.pause();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return barcodeView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
    }
}

@@ -55,17 +55,179 @@
 oid.
-os.Bundle
+Manifest;%0Aimport android.content.pm.PackageManager;%0Aimport android.os.Bundle;%0Aimport android.support.v4.app.ActivityCompat;%0Aimport android.support.v4.content.ContextCompat
 ;%0Aim
@@ -1743,32 +1743,482 @@
 this);%0A%0A%0A    %7D%0A%0A
+    private void checkPermission() %7B%0A        // Here, thisActivity is the current activity%0A        if (ContextCompat.checkSelfPermission(this,%0A                Manifest.permission.CAMERA)%0A                != PackageManager.PERMISSION_GRANTED) %7B%0A%0A            ActivityCompat.requestPermissions(this,%0A                    new String%5B%5D%7BManifest.permission.CAMERA%7D,%0A                    1);%0A        %7D else %7B%0A            barcodeView.resume();%0A        %7D%0A    %7D%0A%0A
     @Override%0A  
@@ -2282,34 +2282,31 @@
         
-barcodeView.resume
+checkPermission
 ();%0A    

add checkPermission to check permission before use camera