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

Community
  • 1
  • 1
ravi
  • 2,722
  • 7
  • 25
  • 42
  • possible duplicate of [How can I read qr code inside GDK app?](http://stackoverflow.com/questions/20831835/how-can-i-read-qr-code-inside-gdk-app) – Tony Allevato Jan 09 '14 at 17:09

6 Answers6

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

StanleyZheng
  • 4,008
  • 3
  • 21
  • 24
  • How can I use BarcodeEye as an intent from my own application? – calumb Jan 12 '14 at 00:30
  • 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. http://stackoverflow.com/questions/1977243/launching-external-application-from-my-app – StanleyZheng Jan 12 '14 at 01:33
  • 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. – calumb Jan 12 '14 at 01:58
  • 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... – calumb Jan 12 '14 at 02:11
  • What is your use case @calumb 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. – StanleyZheng Jan 12 '14 at 15:11
  • 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. – calumb Jan 13 '14 at 22:18
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);
}
StanleyZheng
  • 4,008
  • 3
  • 21
  • 24
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)

Rakesh
  • 2,732
  • 29
  • 28
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]);
                }
            }
        }
    }

}
}
Nehalkumar
  • 227
  • 2
  • 15
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 :)

Abhinava
  • 1,030
  • 9
  • 19
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

user2858559
  • 39
  • 1
  • 9