I am trying to make Google Now accept custom commands and send an Intent to my app when a particular query is made.
I did this successfully using Tasker and Autovoice, but I want to do the same without using these apps.
I found this link to the documentation. Where can I handle common intents which did not fulfill my task.
I also tried the Voice Interaction API provided by Google, which is almost the same thing, but this did not help.
Has anyone here achieved this without using other apps like Commander, Autovoice or Tasker?
Google Now does not currently 'accept' custom commands. The apps you detail use an AcccessibilityService 'hack' to intercept the voice command, or for rooted devices, the xposed framework.
They either then act upon them, simultaneously killing Google Now, or ignore them and allow Google to display its results as usual.
For many reasons, this is a bad idea:
Disclaimer complete! Use at your own risk....
You need to register an
AccessibilityServicein theManifest:And add the config file to
res/xml:You can optionally add:
or extend the functionality by adding further event types:
Include the following
AccessibilityServiceexample class:I made the class as verbose an indented as possible, so it's hopefully easier to follow.
It does the following:
To test:
Servicein the Android Accessibility SettingsThe above will demonstrate the extracted text/command from both hard-coded views. If you don't restart Google Now, the command will still be detected as interim.
Using the extracted voice command, you need to perform your own language matching to determine if this is a command you are interested in. If it is, you need to prevent Google from speaking or displaying the results. This is achieved by killing Google Now or sending it an empty voice search intent, containing flags that should
clear/reset task.You will be in a race-condition doing this, so your language processing needs to be pretty smart, or pretty basic....
Hope that helps.
EDIT:
For those asking, to 'kill' Google Now, you either need to have permission to kill processes, or send an empty ("") search intent to clear the current search: