How to scan a QR code using Google Glass?
Asked Answered
S

6

7

I want to create a Google glass application in which i want to scan a QR code.

I went through this post but i couldn't get clear idea.

Read QR code

Can anyone please direct me how to scan a QR code and get its content in Google Glass.

Thanks

Subzero answered 9/1, 2014 at 11:6 Comment(1)
possible duplicate of How can I read qr code inside GDK app?Millwork
S
4

Instructions are using Android Development version of Eclipse.

Glass is running a version of Android 4.0.3. You can slideload an app using an .apk

This project, Barcode Eye, ports the ZXing project to Google Glass https://github.com/BarcodeEye/BarcodeEye

After you clone the repo, add GDK, and build you can port it to your device.

It has hooks for Amazon, Ebay and Google in it already

Schindler answered 10/1, 2014 at 19:32 Comment(6)
How can I use BarcodeEye as an intent from my own application?Skyscraper
I'm still working through this but look at the structure how the current app handles other requests. Here's a lead on external intents. #1977743Schindler
Hmmm, well I am able to start BarcodeEye from my app no problem. But the standard intent return actions must have been removed. I have trouble, calling setResult in the correct location and handing control back to my application. Currently BarcodeEye just keeps running no matter what I do.Skyscraper
I seem to have gotten it to return the text from my QR but it is extremely hacky and probably wont work in all cases...Skyscraper
What is your use case @Skyscraper that you are trying to accomplish? If you mean the barcode scanner continuously running, maybe look into the intents in the manifests and changing the settings. I see you are trying to access location information also. I am still quite a novice at Android programming.Schindler
My usecase is that I want to create QR codes that will work with my app. So basically just scan text and then retrieve it back in my app. I was able to get this setup by adding intent filters and a return intent to the BarcodeEye app, but I dont think it would work in all cases.Skyscraper
S
3

Here is a good solution I found later on.

Here is how to start a basic glassware that starts the QR scanner, returns a result, and sets it as the view card.

Basic program, just the section

protected void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState);

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

    Card card1 = new Card(this);
    card1.setText("Spoken Words!");
    card1.setFootnote("my app");
    View card1View = card1.toView();
    setContentView(card1View);
    setDisplayCard(card1);
}

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

    }
    super.onActivityResult(requestCode, resultCode, data);
}
Schindler answered 19/2, 2014 at 20:36 Comment(1)
But you have to install Zxing before it on Glass'es. Without it will just ask you to do it.Kutchins
P
2
Intent objIntent = new Intent("com.google.zxing.client.android.SCAN"); 
        objIntent.putExtra("SCAN_MODE", "QR_CODE_MODE"); 
        startActivityForResult(objIntent, 0);

Check if this will work for you, it is working on ADT (Mobile)

Papilloma answered 22/1, 2014 at 9:18 Comment(0)
C
2
package com.metaio.example_internal;

import android.os.Bundle;
import android.widget.TextView;

import com.metaio.sdk.ARViewActivity;
import com.metaio.sdk.MetaioDebug;
import com.metaio.sdk.jni.IGeometry;
import com.metaio.sdk.jni.IMetaioSDKCallback;
import com.metaio.sdk.jni.TrackingValues;
import com.metaio.sdk.jni.TrackingValuesVector;

public class QRCodeReader extends ARViewActivity
{
/**
 * Text view that will display bar code data
 */
private TextView mText;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    mText = new TextView(this);
    mGUIView = mText;
}

@Override
protected int getGUILayout() 
{
    return 0;
}

/**
 * Display a text on screen
 * @param data String to be displayed
 */
private void displayText(final String data)
{
    runOnUiThread(new Runnable()
    {
        @Override
        public void run() {

            mText.setText(data);
        }

    });
}

@Override
protected IMetaioSDKCallback getMetaioSDKCallbackHandler() 
{
    return new MetaioSDKCallbackHandler();
}

@Override
protected void loadContents() 
{   
    // set QR code reading configuration
    final boolean result = metaioSDK.setTrackingConfiguration("QRCODE");
    MetaioDebug.log("Tracking data loaded: " + result);
}

@Override
protected void onGeometryTouched(final IGeometry geometry) 
{

}

final class MetaioSDKCallbackHandler extends IMetaioSDKCallback
{       
    @Override
    public void onTrackingEvent(TrackingValuesVector trackingValues)
    {
        if (trackingValues.size() > 0)
        {
            final TrackingValues v = trackingValues.get(0);

            if (v.isTrackingState())
            {   
                final String[] tokens = v.getAdditionalValues().split("::");
                if (tokens.length > 1)
                {
                    displayText("QR Code detected: "+tokens[1]);
                }
            }
        }
    }

}
}
Congest answered 21/3, 2014 at 9:22 Comment(0)
P
1

Have recently launched a modified version of zxing library known as BarcodeFragLib, The library is compatible for any form factor and have tested it my self to work on Google Glass :) You can find the implementation sample and code is available at https://code.google.com/p/barcodefraglibv2/wiki/HowTo

Hope this helps :)

Psychopathist answered 1/6, 2014 at 3:39 Comment(0)
T
0

which libraries have to be included to the own glass app if I want to run the scanner? What I did so far was to get this here: https://github.com/BarcodeEye/BarcodeEye The project works fine on glass :)

Greetings

Trilobate answered 6/11, 2014 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.