Search Unity

How to build for Google Glass

Discussion in 'Android' started by bliprob, Dec 26, 2013.

  1. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    I recently got my hands on Google Glass and had to try building a game for it. I took my old augmented reality iOS tech demo and gave it spin on the Glass.

    The unit itself is based on Android 4.0.3 (API 15) with a 640 x 360 display. The GPU is a PowerVR SGX540 -- like in the Galaxy Nexus, less powerful than an iPhone 4S. Accelerometer and gyro worked as expected. Touches on the temple pad can be detected via AndroidInput.touchCountSecondary and AndroidInput.GetSecondaryTouch().

    How to build from Unity for Google Glass:

    1. Switch build platform to Android, and set Player Settings > Minimum API Level to "API 15"
    2. Set the orientation to "Landscape Left"
    3. Optional settings: Set the Game preview window size to 640 x 360. Set the Camera field of view to 17°.
    4. Don't let the screen go to sleep, because there's no way back to an immersion, except to re-launch the app from "OK Glass":

    Code (csharp):
    1.     Screen.sleepTimeout = SleepTimeout.NeverSleep;
    5. Create a voice trigger. This lets you start your game with the "OK Glass, play a game" command. Create folders "Assets/Plugins/Android/res/values" and "Assets/Plugins/Android/res/xml".
    Create Plugins/Android/res/xml/my_voice_trigger.xml:
    Code (csharp):
    1.         <?xml version="1.0" encoding="utf-8"?>
    2.         <trigger keyword="@string/glass_voice_trigger">
    3.         </trigger>
    4.  
    Create Plugins/Android/res/values/strings.xml:
    Code (csharp):
    1.         <?xml version="1.0" encoding="utf-8"?>
    2.         <resources>
    3.           <string name="app_name">@string/app_name</string>
    4.           <string name="glass_voice_trigger">play a game</string>
    5.         </resources>
    6.  
    Copy the default AndroidManifest.xml from inside the Unity app bundle (/Applications/Unity/Unity.app/Contents/PlaybackEngines/AndroidDevelopmentPlayer) to Assets/Plugins/Android. Then, add this to the manifest inside the activity tag:

    Code (csharp):
    1.             <intent-filter>
    2.                 <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
    3.             </intent-filter>
    4.             <meta-data android:name="com.google.android.glass.VoiceTrigger" android:resource="@xml/my_voice_trigger" />
    5.  
    7. File > Build and Run with the device connected.


    -- Rob
     
    ROBYER1 likes this.
  2. ant001

    ant001

    Joined:
    Dec 15, 2010
    Posts:
    116
    thanks
     
  3. LoftyTheMetroid

    LoftyTheMetroid

    Joined:
    Oct 26, 2012
    Posts:
    57
    First, I just wanted to say thanks! I'm doing an AR project for my class and this thread really helped me, so thank you for making it. I have successfully managed to deploy my Vuforia-based Unity application to Glass, but I'm having a small problem.

    Currently, I can only deploy to Glass if I selected "Build and Run". However, if I just "Build" and try to install the resulting APK via ADB, the application will immediately exit and say something to the effect of "Project has stopped working". I have the same issue if I try selecting the installed app after "Build and Run"; while the initial run of the app works, I can't run it again from the Glass menu.

    In trying to isolate the issue and see if it was due to Vuforia, I duplicated the project and removed everything related to Vuforia. Strangely enough, that project won't deploy to Glass at all, even if I select "Build and Run".

    Anybody have this issue or have an idea what it could be? Is this a Glass-specific problem, or could there be an Android-related explanation?
     
  4. poshaughnessey

    poshaughnessey

    Joined:
    Jul 12, 2012
    Posts:
    45
    Nice overview!

    One thing that has changed since you wrote your original post is that you'll need to add the following permission to your AndroidManifest.xml if you are using an unapproved voice trigger:

    Code (CSharp):
    1. <uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
     
  5. oinkoinkflapflap

    oinkoinkflapflap

    Joined:
    Jul 29, 2012
    Posts:
    4
    First off, thanks allot! This tutorial really helped me get my game on the glass! And it works great, feels great the first time you see that 'powered by unity' finally appear! But how would i get my game perminantly on the glass? so to use it away from the computer i can "ok glass" "play a game with" and it be there? do I have to send the game with some kind of file transfer? First time I've worked with the Glass, and i don't know it that well, thanks again for the great post!
     
  6. oinkoinkflapflap

    oinkoinkflapflap

    Joined:
    Jul 29, 2012
    Posts:
    4
    To help any others that might have the same trouble, my problem was just that i hadn't done the Android Manifest properly, now it works fine! it's under play a game
     
  7. EngAlOtaibi

    EngAlOtaibi

    Joined:
    Oct 9, 2014
    Posts:
    2
    Hi everyone ,

    I need some help.

    I am managing to merge the unity within a menu that will be displayed that will run on Google Glass .

    This is my class MenuActivity.java


    Code (JavaScript):
    1. package com.morkout.glasswaretemplate;
    2.  
    3.  
    4. import java.util.HashMap;
    5. import java.util.Locale;
    6. import java.util.logging.Handler;
    7.  
    8. import com.unity3d.player.UnityPlayer;
    9. import com.unity3d.player.UnityPlayerActivity;
    10.  
    11.  
    12. import android.app.Activity;
    13. import android.app.PendingIntent;
    14. import android.content.Intent;
    15. import android.os.Bundle;
    16. import android.speech.RecognizerIntent;
    17. import android.speech.tts.TextToSpeech;
    18. import android.speech.tts.TextToSpeech.OnInitListener;
    19. import android.speech.tts.UtteranceProgressListener;
    20. import android.util.Log;
    21. import android.view.Menu;
    22. import android.view.MenuInflater;
    23. import android.view.MenuItem;
    24. import android.view.View;
    25.  
    26. public class MenuActivity extends Activity implements OnInitListener {
    27.     private static final String TAG = "MenuActivity";
    28.     private TextToSpeech tts;
    29.     private boolean mAttachedToWindow;
    30.     private boolean mTTSSelected;
    31.     final long delay = 5000;//ms
    32.  
    33.     @Override
    34.     protected void onCreate(Bundle savedInstanceState) {
    35.         super.onCreate(savedInstanceState);
    36.         mTTSSelected = false;
    37.     }
    38.  
    39.     @Override
    40.     public void onAttachedToWindow() {
    41.         super.onAttachedToWindow();
    42.         mAttachedToWindow = true;
    43.         openOptionsMenu();
    44.     }
    45.  
    46.     @Override
    47.     public void onDetachedFromWindow() {
    48.         super.onDetachedFromWindow();
    49.         mAttachedToWindow = false;
    50.     }
    51.  
    52.     @Override
    53.     public void openOptionsMenu() {
    54.         if (mAttachedToWindow) {
    55.             super.openOptionsMenu();
    56.         }
    57.     }
    58.  
    59.     @Override
    60.     public boolean onCreateOptionsMenu(Menu menu) {
    61.         MenuInflater inflater = getMenuInflater();
    62.         inflater.inflate(R.menu.main, menu);
    63.  
    64.         return true;
    65.     }
    66.  
    67.  
    68.     @Override
    69.     public boolean onOptionsItemSelected(MenuItem item) {
    70.         switch (item.getItemId()) {
    71.         case R.id.stop:
    72.          
    73.              [COLOR=#ff0000]// This is the option when clicked I want the unity Game to start [/COLOR]
    74.             return true;
    75.  
    76.         case R.id.tts:
    77.             mTTSSelected = true;
    78.             tts = new TextToSpeech(this, this);
    79.             tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
    80.                 @Override
    81.                 public void onDone(String utteranceId) {
    82.                     Log.w(TAG, "onDone");
    83.                     if (tts != null) {
    84.                         tts.stop();
    85.                         tts.shutdown();
    86.                     }              
    87.                     finish();
    88.                 }
    89.  
    90.                 @Override
    91.                 public void onError(String utteranceId) {
    92.                     Log.w(TAG, "onError");
    93.                 }
    94.  
    95.                 @Override
    96.                 public void onStart(String utteranceId) {
    97.                     Log.w(TAG, "onStart");
    98.                 }
    99.             });
    100.             return true;
    101.  
    102.  
    103.         default:
    104.             return super.onOptionsItemSelected(item);
    105.         }
    106.     }
    107.  
    108.  
    109.     @Override
    110.     public void onOptionsMenuClosed(Menu menu) {
    111.         if (!mTTSSelected)
    112.             finish();
    113.     }
    114.  
    115.  
    116.     @Override
    117.     public void onInit(int status) {
    118.         if (status == TextToSpeech.SUCCESS) {
    119.             int result = tts.setLanguage(Locale.US);
    120.  
    121.             if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
    122.                 Log.e("TTS", "This Language is not supported");
    123.             } else {
    124.                 HashMap<String, String> map = new HashMap<String, String>();
    125.                 map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"helloID");            
    126.                 tts.speak("Hello Glass!", TextToSpeech.QUEUE_FLUSH, map);
    127.             }
    128.         } else {
    129.             Log.e("TTS", "Initilization Failed!");
    130.         }
    131.     }
    132.  
    133.  
    134. }
    135.  
    I followed this steps in importing unity to eclipse

    1. Start with an Android project which will contain all the Android bits.
    2. Prepare the Unity3d Android project. Import the Unity project into your workspace like a regular Android project.
    3. RMB on the Unity project, click “Properties”, then go to “Android” and tick the “Is Library?” check box.
    4. RMB on the Android project, click “Properties”, then go to “Android” and click “Add” to add a library - the Unity project - to the Android one.
    5. Still in the “Properties” dialog, go to “Java Build Path” and select the “Libraries” tab. There, click “Add external JAR” and navigate to the classes.jar file.
    6. Ensure both projects target the same SDK.
    7. Move the “assets” folder from the Unity project into the Android project. This step has to be repeated each time your Unity project is rebuilt.

    Now I need help in calling Unity Game inside my menuActivity.java

    Can anyone help me plz

    Regards
    AA
     
  8. IntARMedia15

    IntARMedia15

    Joined:
    May 27, 2015
    Posts:
    2
    Quick question: Where would I put the "No sleep" and voice command opening codes. Please help asap just got Google glass and testing with an AR idea