سؤال

I have an android app developed to run on the google glass. And I run it using the adb. is it possible to give configure a voice command so that I can trigger it by saying "Ok GLASS" + "My Command" ??

هل كانت مفيدة؟

المحلول

Update - After XE16 update the following method does not work, the new solution is here Why is my voice command missing from the ok glass menu in XE16?

What you have to do is,

  1. Inside the manifest file add these tags under the service which you wanted to trigger on your voice command.

    <intent-filter>
        <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
    </intent-filter>
    <meta-data
        android:name="com.google.android.glass.VoiceTrigger"
        android:resource="@xml/voice_trigger_start" />
    
  2. And you have to create a folder called xml inside res and add a xml file named as voice_trigger_start.xml.

  3. Inside that add these lines

    <?xml version="1.0" encoding="utf-8"?>
    <trigger keyword="@string/its_me_amalan" />
    
  4. Open the values folder inside the res folder and edit strings.xml, so it will look like this

    <resources>
        <string name="app_name">Amalan</string>
        <string name="its_me_amalan">Hello Amalan</string>
        <string name="stop">Stop</string>
    </resources>
    

Now install the app onto Glass and say "ok glass, Hello Amalan" and the app opens.

Reference: http://pathofacoder.com/2013/11/20/google-glass-adding-your-own-voice-commands-to-your-apps/

نصائح أخرى

Yesterday, Google released the XE12 firmware update, which put us into trouble with all custom launchers. Both Launcher2.apk and Launchy stopped working for me so as a workaround I implemented a method which is also a good answer to your question. Take a look at this page http://divingintoglass.blogspot.com/

I did this for a Glassware app developed with the GDK in this commit: https://github.com/luisdelarosa/HelloGlass/commit/c5038ed2ff019306becb32211354358833b6fafc

Here is what is in that commit step-by-step:

Modify the AndroidManifest.xml to add a VoiceTrigger intent, inside either the Activity or the Service you want to launch via voice. Note that you can also optionally delete the Launcher intent since Glass does not use those like traditional Android.

<intent-filter>
    <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
    android:name="com.google.android.glass.VoiceTrigger"
    android:resource="@xml/glass_voice_trigger" />

Add the VoiceTrigger XML that the VoiceTrigger intent references, which should contain the string that you want the user to activate your app. In this case, we're calling it res/xml/glass_voice_trigger.xml

<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_voice_trigger"/>

Optionally, put the string in the previous step into a strings.xml file. (You could have also just hardcoded that string into the VoiceTrigger XML as the value of the keyword attribute of the trigger node.) In this case, it is at res/values/strings.xml and our trigger is "say hello". Replace this string with whatever you want the user to say to launch your app.

<string name="glass_voice_trigger">say hello</string>

Don't forget to use permission since XE16 :

<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top