DIY Earphones for Google Glass

Google Glass v1 (and v2) is capable of playing audio through the micro-USB connector that is used to charge the device.

To make your own earphones for Google Glass, you will need either 1 or 2 earphones, a 500K Ohm resistor, and a 5 pin micro-USB connector. I did not have a 500K Ohm resistor available, and used a 470K Ohm instead. It seems to do the job without any problems.

With the connector laying down, and the 2 pins facing upward, the pinout is as follows:

Pin 1: +5VCC (Not Used in this DIY)
Pin 2: D- (Audio Left Channel)
Pin 3: D+ (Audio Right Channel)
Pin 4: ID (500K resistor connects to GND)
Pin 5: GND (Ground)

Connect the resistor to pins 4 and 5.

Cut the wires from your existing earphones as long as you need them to be.

If you are using a single earphone (mono), you should bridge pins 2 and 3. With mine, I used part of the lead that I cut from the resistor. Connect the positive wire from the earphone to pin 2, and the ground to pin 5.
If you are using two earphones (stereo), connect the wire from the left earphone to pin 2, and the right earphone to pin 3. The ground wire should connect to pin 5.

Note that pin 1 is not used.

This is the micro-USB connector with pins 1, 3, and 5 facing upward.

Verify your work, and check for shorts or bare wires touching.
Close up the micro-USB connector, and you are ready to use your earphones. You can probably fill the connector with epoxy to ensure that if a wire were to loosen, that it will not short.

This is the finished micro-USB connected to my Glass.

DISCLAIMER: I can not be held responsible if you do this wrong, or if your device gets damaged.


Install Oracle Java 7 on Ubuntu (11, 12, and 13)

Before you can install the Oracle version of Java, it is recommended to uninstall OpenJDK. To do this, you can run the following command in the terminal:

    sudo apt-get purge openjdk*

Now add the PPA to Ubuntu and install Java:

    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer

Android ListView and ArrayIndexOutOfBoundsException

While working on an app with a native Navigation Drawer, I noticed that on Android 4.0.4 my app crashes. I could not get this exception on any other version of Android.

    java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
    at android.widget.AbsListView$RecycleBin.addScrapView(
    at android.widget.AbsListView.trackMotionScroll(
    at android.widget.AbsListView$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(

After spending about an hour trying to figure this out, I realized that my Adapter for the List View returned a value of 2 from the getViewTypeCount() method, and getItemViewType() returned a value of 1, or 2, depending on the type of view. The getItemViewType() is suppose to start with a value of 0, so it should be returning a value of 0 or 1, instead.

For example:

public class ActionBarDrawerAdapter extends BaseAdapter {
    public int getViewTypeCount() {
        return 2;
    public int getItemViewType(int position) {
        ActionBarDrawerItem item = (ActionBarDrawerItem) getItem(position);
        if (item.isSubnavItem()) {
            return 1;
        } else {
            return 0;

Adding kSOAP 2 to your Android Gradle project

I am working on an app that needs to communicate with a server using SOAP messages. I decided to use the kSOAP2-Android library, since is seems to be the most robust way to handle SOAP calls in Android.

To add the library as a dependency to your project, download the kSOAP2-Android JAR file into the libs directory in the project. (At the time of writing this, version 3.0 were the most current version)

Open the Gradle build file ( and add the kSOAP dependency (your dependencies block should look something like this)

dependencies {
    compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')

Now all you need to do is to clean the project.  That can be done from the command line, or from the Android Studio IDE.  From the command line, in your project directory, run “./gradlew clean”, then rebuild and run your app.

Screen Shot 2013-01-17 at 10.46.49 AM

Installing and Configuring the Google TV Emulator

The Google TV developers released a GoogleTV add-on for the Android SDK that makes emulation possible on the Windows and Mac Operating Systems (Linux was already supported).

Assuming that you have the Android SDK already installed:

In order to use the emulator, you need to open the Android SDK Manager and make sure that you have the “Google TV Addon” [under Android 3.2 (API 13)] and the “Intel Atom x86 System Image” [under Android 2.3.3 (API 10)].


If you installed the “Intel Atom x86 System Image”, you need to install the “Intel Hardware Accelerated Execution Manager” which can be found in the <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/
For Windows, install the IntelHAXM.exe file.  
For Mac, install the IntelHAXM.dmg file.
You can read the installation instructions here

Create a new “Device Definition” in the “Android Virtual Device Manager” using the configuration below.  
For 1080p use a resolution of 1920×1080 and a density of xhdpi.
For 720p use a resolution of 1080×720 with a density of tvdpi.


Then create a “Android Virtual Device” using the “Device Definition” that you just configured.


Google TV Logo

What is Google TV

What is Google TV?
Google TV is an Android based platform that brings live TV, web and android apps all together in one device. It is like having a computer, cell phone, and television all in one.

Why develop for Google TV?
Did you know that the average person watches 5 hours of television every day? Due to this large amount of TV watching about 20% of televisions sold in 2010 were internet ready. Having this Google TV platform gives you the ability to develop apps that will enhance the TV viewing experience for millions of viewers. For example an app focused on sports can bring the most up to date statistics, video content and game scores to each viewer on personal demand.

Does developing for Google TV intrigue you? Well if it does then my next post will take you through the steps of how to get your Google TV development experience started.


Adding a hook to the PHP output headers

With PHP 5.4 you can now easily add a callback function, using header_register_callback, to be called just before the headers are sent to the browser.

For example:

  header('Content-Type: text/plain');
  header('X-Test: test-header');

  header_register_callback( 'remove_XPoweredBy_header' );

  echo 'Testing';

This allows you to set a callback function, in this case, remove_XPoweredBy_header.

An example of something to do in this callback function:

  function remove_XPoweredBy_header()

This will prevent “X-Test” from showing up in the headers.


Getting and Setting HTTP Response codes in PHP 5.4

A new function were added to PHP 5.4 that make getting and setting HTTP response code easy.

To get the current HTTP code, all you have to do is call the http_response_code function

  echo http_response_code()  //If all is ok, this should echo 200

To set the HTTP response code, add a parameter to the http_response_code function

  echo http_response_code()  //This should echo 404 and return 404 in the header

Class Member Access on Instantiation with PHP 5.4

Class members can now be accessed on instantiation in PHP 5.4. This is a very handy addition.
Before PHP 5.4 you had to create an object into a variable, and then access the class member/function:

  //The old way
  $object = new SomeClass();

With PHP 5.4 you can access the class member directly on instantiation:

  //The new way
  (new SomeClass)->someFunction();

Function Array Dereferencing in PHP 5.4

PHP now supports array dereferencing directly from a function call. Before PHP 5.4 you had to store the returning value from a function into a variable, and then use the variable.

  $cars = $explode(",", "ferrari,lamborghini,maserati,bugatti");
  echo $cars[3];  //bugatti

Now with PHP 5.4 you can do it like this:

  echo $explode(",", "ferrari,lamborghini,maserati,bugatti")[3];  //bugatti

Another example with your own function:

  function get_cars()
    return ["ferrari","lamborghini","maserati","bugatti"];
  echo get_cars()[3];  //bugatti