Aprender a programar Arduino, iOS, Android & Google Glass!

First Google Glass App – Part 7 – Bridge to Glass App GDK Development

Before jumping into Glass dev, let’s understand how to create a Hello World project in Android Studio (AS) and run it on our device.

Create New Project

Get to know the guts

Add Imports

Add Code

Tweak guts

Run on Device

Create New Project

When you select New Project from the File Menu, you get this Wizard screen:

Android Studio Beginner App Development

Fill in the Application Name in a natural language and the Module Name without spaces. Make sure to select API 15 for Minimum and Target SDK but Glass Development Kit Sneak Peek for Compile with.

Click Next and in the next screen just leave everything as is (the launch icon selector screen).

Android Studio Project Launcher Icon Window

After that screen, leave the Blank Activity option selected and again click Next.

Android Studio Project Blank Activity Window

Finally in the Activity Name, leave MainActivity. In the Layout Name leave activity_main but also copy that activity_main over to the Fragment Layout Name, replacing fragment_main.

Android Studio Project Layout Window

Everything else stays as is and Click Finish. The reason for this last bit is that new in Android is this concept of Fragments. This just complicates things for us at the moment so we will leave it out for now. We must also remove the MainActivity.java fragment method later.

Android Guts

Let’s familiarize ourselves with this screen:

Android Studio Layout Google Glass Development

Let’s review these 10 top pointers:

Your Java Classes or Android Activities

Layout files in xml format

Value files for storing global settings of sorts

AndroidManifest is a sort of Central Registry

Top level build.gradle file

Low level build.gradle file

Tab bar for displayed files

Sync Gradle file button

Run button

Green = A-Ok button!

Take some time to explore these files. If you have gone through the tutorial at:

You will be familiar with these pointers. Otherwise, let’s take a closer look.

MainActivity is selected and displayed in the editor window. This contains your default, boilerplate/template created MainActivity Class required for any app.

The layout folder contains your activity_main.xml file. If you look inside that file you will see an xml file with some parameters and a TextView element. You will also see a graphical representation of it off to the far right.

The values folder contains more xml files. Most importantly, the strings.xml which contains global references to string values. These are used throughout the app to assign string values where needed.

The AndroidManifest.xml file contains some general settings elements for your app such as the package name, launcher icon, activity tags which contain your declared activities and in this case, if the activity has an intent, which is like an action, it must also be specified here. In our case we will add a Voice Trigger intent filter if there isn’t one already.

Build.gradle files are not to be messed around with much. This is a new M.O. used by Android Studio to organize files in a workspace. You must keep in mind here that there is a Top level and Low level build.gradle file so make sure you know which one you are being told to put things in.

The tabs display whatever files you have double clicked on the File Window on the left.

The Sync Gradle button is that green-blue circle with a solid circle inside and a green arrow pointing down. Go Figure! Its basically a sort of I’ve-made-some-changes-to-the-AndroidManifest-and/or-other-project-wide-parameters-which-require-project-workspace-reindexing (phew) button!

The Run button is of course the one used to build and launch the app in the emulator or device.

The Green=AOk button tells you all file and project inconsistencies have been resolved and that the project will build and run. Sometimes you have resolved coding issues and this box is still red. Just tap on the Sync Gradle button mentioned before and Just Like That, Its Magic…AOk!

Great now let’s look at some code…

Imports

If you expand the imports “+” sign in the MainActivity window’s left edge, you will get a list of what imports a project comes with. Let’s just make sure they look like this:

Hi there, just became aware of your blog thru Google, and located that it’s truly informative. I am gonna be careful for brussels. I will be grateful if you happen to continue this in future. A lot of people can be benefited from your writing. Cheers!