< back to Code

A native Android mobile application I created in Android Studio to provide links from exhibited artwork to their online content.

"Rich's Art Code Scanner" onscreen. Note the round richcarthew logo 

I recently updated this application for my Samsung Galaxy A20. My original idea was to generate and print out small QR-codes and paste them in strategic places within my art journals, that when scanned, would display links to relevant content on this site, such as videos and animations.

I was just going to download a simple 'free' QR-code reader from the web, but the 3 or 4 ones I found all came with the usual annoying bloatware, ads and also wanted access to my contacts and my location etc, presumably to harvest data in the background to sell to 3rd parties - these permissions are NOT needed for the application to function. Developers (like me) do need to eat and pay the bills, hence the ads etc, but I ended up deciding to invest the time and build my own from scratch. This turned out to be a bigger project than I anticipated, however I really love the end product:

  • Custom built with my own artwork, graphics and wallpaper
  • Personalized richcarthew logo (find all the letters in the blue circle!)
  • Lightweight code
  • ZERO ads!
  • 100% trustworthy (no background data harvesting etc)
  • Great tie-in to the S.T.E.A.M movement which is my creative area
  • Satisfaction of having built it myself

The only components that a QR and Barcode scanner in Android need are these:

<uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Android Studio IDE.

Screen shot of the current layout design of my QR code reader. A bunch of linked files make up the app, this particular one is activity_main.xml used for laying out the screen elements.


The main code file that pulls it altogether is  MainActivity.java and this imports all the necessary code libraries (dependencies)

Below is the Java code:

package com.richcarthew.barcodereadersample;

import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.common.api.CommonStatusCodes;
import com.google.android.gms.vision.barcode.Barcode;
import com.richcarthew.barcodereadersample.barcode.BarcodeCaptureActivity;

public class MainActivity extends AppCompatActivity {
    private static final String LOG_TAG = MainActivity.class.getSimpleName();
    private static final int BARCODE_READER_REQUEST_CODE = 1;

    private TextView mResultTextView;

    protected void onCreate(Bundle savedInstanceState) {

        //create a view on phone screen to begin
        mResultTextView = (TextView) findViewById(R.id.result_textview);

        Button scanBarcodeButton = (Button) findViewById(R.id.scan_barcode_button);
        scanBarcodeButton.setOnClickListener(new View.OnClickListener() {

            //create new intent activity that uses the camera to scan the bar/QR code
            public void onClick(View view) {
                Intent intent = new Intent(getApplicationContext(), BarcodeCaptureActivity.class);
                startActivityForResult(intent, BARCODE_READER_REQUEST_CODE);

    // process captured image and return relative link in richcarthew.com/*
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == BARCODE_READER_REQUEST_CODE) {
            if (resultCode == CommonStatusCodes.SUCCESS) {
                if (data != null) {
                    Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                    Point[] p = barcode.cornerPoints;
                    mResultTextView.setText("Click the link to view: \n \n " + barcode.displayValue + "\n");
                } else mResultTextView.setText(R.string.no_barcode_captured);
                //if error, indicate that in the TextView
            } else Log.e(LOG_TAG, String.format(getString(R.string.barcode_error_format),
        } else super.onActivityResult(requestCode, resultCode, data);

< back to Code