Search code examples
barcode-scannergoogle-gdk

Barcode Scanner doesn't work on Glass GDK


I am new to Glass GDK development and I have a problem with scanning a barcode. I have followed this(http://blog.wombatsoftware.de/2014/01/running-zxing-qr-code-engine-on-google.html) post but my barcode scanner still doesn't work. it looks like a photo attached. I had a look also on BarcodeEye project but I don't understand how can I integrate it with my project. Can you please help me?

CameraConfiguration

   public void googleGlassInit(Camera camera) {
      Camera.Parameters params = camera.getParameters();
      params.setPreviewFpsRange(30000, 30000);
      params.setPreviewSize(640,360);
      camera.setParameters(params);
    }
    void setTorch(Camera camera, boolean newSetting) {
        Camera.Parameters parameters = camera.getParameters();
        doSetTorch(parameters, newSetting, false);
        camera.setParameters(parameters);
        googleGlassInit(camera); // added this line
       // googleGlassXE10WorkAround(camera);
    }
...

MainActivity.java

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

        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
         intent.setPackage("com.google.zxing.client.android");
         intent.putExtra("SCAN_MODE","QR_CODE_MODE");
         startActivityForResult(intent,0);  

        }

        //when a QR code is read, it will send a result code 
            protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
             if (requestCode == 0 && resultCode == RESULT_OK){
                String contents = data.getStringExtra("SCAN_RESULT");
                Card card1 = new Card(this);
                card1.setText(contents);
                card1.setFootnote("zxing");
                View card1View = card1.getView();
                setContentView(card1View);
            //    setDisplayCard(card1);

            }
            super.onActivityResult(requestCode, resultCode, data);

    }

enter image description here



Solution

  • In CameraConfiguraionManager you also need to add googleGlassInit(camera) in setDesiredCameraParameters.

    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
    camera.setParameters(parameters);
    googleGlassInit(camera); // added this line
    
    Camera.Parameters afterParameters = camera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    

    I hope this help you! This works for me :)

    PD: I also use 640x360 so that shouldn't be a problem.