Skip to content
Arvydas Juskevicius edited this page Jan 20, 2015 · 4 revisions

Welcome to the BlinkStick for Android wiki!

This is an official implementation of BlinkStick API for Android devices running Android 4.0 and later version.

Hardware requirements

In order to use BlinkStick with Android device you will need:

  • Device running Android 4.0 or later
  • Device must support USB OTG, for example Google Nexus 7
  • USB OTG cable
  • Any BlinkStick device

Downloading Library

You can clone the library as a git submodule or download full source code.

API reference documentation

API reference documentation is available online:

http://arvydas.github.io/blinkstick-android/

Quick start guide for using the library

Add reference to the library in your IDE. Use the code sample below to integrate BlinkStick with your Android application.

import com.agileinnovative.blinkstick.BlinkStick;
import com.agileinnovative.blinkstick.BlinkStickFinder;
import com.agileinnovative.blinkstick.BlinkStickUnauthorizedException;

public class MainActivity extends Activity {

	private PendingIntent mPermissionIntent;
	private static final String ACTION_USB_PERMISSION = "com.examples.accessory.controller.action.USB_PERMISSION";
	
    BlinkStick led;
    BlinkStickFinder finder;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
		
		finder = new BlinkStickFinder();
		finder.setContext(this);
		finder.setPermissionIntent(mPermissionIntent);
		
		led = finder.findFirst();
		if (led != null)
		{
			try {
				if (finder.openDevice(led))
				{
					Log.d("BlinkStickInfo", "Manufacturer: " + led.getManufacturer());
					Log.d("BlinkStickInfo", "Product: " + led.getProduct());
					Log.d("BlinkStickInfo", "Serial: " + led.getSerial());
					Log.d("BlinkStickInfo", "Color: " + led.getColorString());
					Log.d("BlinkStickInfo", "Mode: " + led.getMode());
				}
			} 
			catch (BlinkStickUnauthorizedException e) {
				finder.requestPermission(led);
			}
		}
	}
	
	private void setColorRed()
	{
		if (led != null) {
			led.setColor(0, 255, 0);
		}
	}
	
	private void sendLedFrameToBlinkStickPro()
	{
		if (led != null)
		{
			byte[] data = new byte[] {(byte)255, 0, 0, 0, (byte)255, 0, 0, 0, (byte)255};
			led.setColors(data);
		}
	}
}