Add Artcodes to your app!

The Artcodes app on the AppStore and Google Play allows you to scan Artcodes and create end-to-end augmented reality experiences. If you need more features or customisation you can add Artcodes to your app by using a library/dependancy or by downloading the code.

Licence

The Horizon Artcodes applications and libraries are publicly distributed under version 3 of the Affero General Public License. If you obtained this code under that license, then all its terms are applicable.

The same applications and libraries are also available under alternative license terms negotiated with the Horizon Digital Economy Research Institute at the University of Nottingham. Contact horizon.NOSPAM@nottingham.ac.uk for more details.

Library/dependancy

Cordova

Cordova is a cross platform development tool that allows you to create mobile apps using HTML, CSS and JavaScript. The Artcodes Cordova plugin only supports iOS and Android.

To install the plugin:

$ cordova plugin add https://github.com/horizon-institute/artcodes-cordova.git --variable IOS_CAMERA_DESC_STRING="We use the camera to scan Artcodes." --save

To use:

function yourFunction() {
	Artcodes.scan(
		{
			name: "Scan screen title", 
			actions: [
				{ codes: ["1:1:3:3:4"] }, 
				{ codes: ["1:1:2:4:4"] }
			] 
		}, 
		function (code) { alert(code); }
	);
}

// like most plugins, Artcodes.scan(...) can only be called sometime after the deviceready event e.g.
document.addEventListener('deviceready', function () {
	yourFunction();
}, false);

Android

Follow these steps to add Artcodes to your Android app. You can also see an example app on GitHub: https://github.com/horizon-institute/artcodes-android-integration-demo.

Step 1: Add Artcodes to your build.gradle dependencies.

compile 'uk.ac.horizon.artcodes:artcodes-scanner:3.3.0'

Step 2: Create an Artcode experience object to pass to the Artcodes scanner.

import uk.ac.horizon.artcodes.model.Experience;
import uk.ac.horizon.artcodes.model.Action;

...

Experience experience = new Experience();
String[] codes = {"1:1:1:1:2", "1:1:2:4:4"};
for (String code : codes)
{
  Action action = new Action();
  action.getCodes().add(code);
  experience.getActions().add(action);
}

Step 3: Start the Artcodes scanner activity.

import android.content.Intent;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import uk.ac.horizon.artcodes.scanner.ScannerActivity;

...

private final int ARTCODE_REQUEST = 12345; // Range: 0-65535

...

Intent intent = new Intent(getApplicationContext(), ScannerActivity.class);

// Put experience in intent
Gson gson = new GsonBuilder().create();
intent.putExtra("experience", gson.toJson(experience));

startActivityForResult(intent, ARTCODE_REQUEST);

Step 4: Handle the response, implement onActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
  if (requestCode == ARTCODE_REQUEST)
  {
    if (resultCode == RESULT_OK)
    {
      // This is where you will receive a response from the
      // Artcode scanner if an Artcode was found
      // Do any logic based on the result here

      // This is the code of the Artcode that was found (e.g. "1:1:1:1:2")
      String code = data.getStringExtra("marker");
    }
  }
}

Note: To access the camera this library will add the “Hardware controls: take pictures and video” permission to your app.

Code on GitHub

The Artcodes app is open source and available on GitHub (version 3 of the Affero General Public License applies):




Leave a Reply