Android Question Google Now Custom commands

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

Just wondering if anyone knows how to register custom phrases/commands into the Google Now app using B4A?

In the Google Now app you can say "OK Google, what is the time" and then it will tell you the time.

What I was wondering if there was a way in my App to register custom things like "OK Google, lets party" and then make it trigger some code in my app.

Anyone know how to do this ?
 

Harmlos

Member
Licensed User
Longtime User
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Hi aaronk,
Do you have installed "open Mic+" already? We can change "OK Google" to our custom commands.
 
Upvote 0

Harmlos

Member
Licensed User
Longtime User
Hi aaronk,
Do you have installed "open Mic+" already? We can change "OK Google" to our custom commands.
thanks for that hint, but this still doesnt work with a wear device... :(
The big advantage of using Google Now an Android wear is: I only have to turn my wrist to start the google now Voice-input on my Moto360. So i dont have to push any button or something to Turn on my lights (they need a UDP message).
till now i am using tasker for Android Wear (which is great too) but i dont want to touch something for this task....
Any other Solutions?

(Hope you can read my German-English XD)
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
https://developers.google.com/voice-actions/system/

I added this

B4X:
<activity ...>
    <intent-filter>
        <action android:name="android.intent.action.SET_ALARM"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

As:

B4X:
AddReceiverText(stimer,
    <intent-filter>
		'voice recognition
        <action android:name="android.intent.action.SET_ALARM"/>
		<action android:name="android.intent.action.SET_TIMER" />
		<action android:name="android.intent.action.SHOW_ALARMS" />
		<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>)
AddReceiverText(stimer,
    <intent-filter>
		<action android:name="android.intent.action.SEND" />
        <category android:name="com.google.android.voicesearch.SELF_NOTE" />
    </intent-filter>)

But my app won't show up in Google now.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I gave it another shot

Manifest:
B4X:
AddApplicationText(<activity android:name=".main">
  <intent-filter>
  <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
  <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
</activity>)

Code in Process_Globals
B4X:
dim StoredIntent As Intent

Code in activity_resume:
B4X:
If Activity.GetStartingIntent <> StoredIntent Then
     StoredIntent = Activity.GetStartingIntent
     Select Case StoredIntent.Action
       Case ""
       Case "com.google.android.gms.actions.SEARCH_ACTION"'Google now search
         If StoredIntent.HasExtra("query") Then  VR_Handle(StoredIntent.GetExtra("query"))' CODE TO HANDLE VOICE COMMAND
       Case Else
         LogColor("ACTION: " & StoredIntent.Action, Colors.Blue)
         LogColor("EXTRAS: " & StoredIntent.ExtrasToString, Colors.Blue)
     End Select
   End If

Then with Google now, you say "Search [name of app] for [search string]"
And the query extra will have the [search string]

THAT was the catch. I didn't know the proper voice command.
Now for the bad news, if your app isn't a known-English word, or if your app is one of those things where you idiotically removed a vowel to sound cool, it won't detect the name properly.
 
Upvote 0
Top