Android Question send command Google assistant

Angelo2016

Member
Licensed User
Longtime User
Hi I found this code snippet and it works, but I would like to send a text command to assistant eg: send("How is the weather today?")
If there is some example please post the link.
Thank you
-----------------------------------------------------
Dim in As Intent
in.Initialize("android.intent.action.VOICE_COMMAND", "")
Try
StartActivity(in)
Catch
Log(LastException)
End Try
-----------------------------------------------------
I found this on the web but I don't know how to insert it...can someone help me??thanks


How to send a text query to Google Assistant:
AssistConfig config = AssistConfig.newBuilder()
    .setTextQuery("Your text query goes here!")
    //.setAudioInConfig(audioInConfig)
    .setAudioOutConfig(audioOutConfig)
    .setDeviceConfig(deviceConfig)
    .setDialogStateIn(dialogStateIn)
    .setScreenOutConfig(screenOutConfig)
    .build();
AssistRequest request = AssistRequest.newBuilder().setConfig(config).build();
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Here is ChatGPT's response:

As of my knowledge cutoff in September 2021, I'm not aware of a way to programmatically send a text query to a device's voice assistant (like Google Assistant) using Basic4Android (B4A).

The VOICE_COMMAND Intent action you're using typically triggers a voice prompt, asking the user to speak a command. The command is not something that's passed in via an Intent extra; it's something that the user speaks after the voice prompt is displayed.

Google Assistant, and most other voice assistants, are designed to receive spoken queries, not text input from another app. The primary way for an app to interact with Google Assistant is through voice interaction, which is not easily automated. The .setTextQuery() method you mentioned earlier is part of the Google Assistant SDK, which is a separate system designed to allow devices to include Google Assistant functionality, and is not intended for sending text queries from one app to Google Assistant on the same device.

While there may be other voice assistants or services that allow for text queries, Google Assistant (which is the most commonly used on Android) does not provide this functionality. It's also important to note that voice assistants can vary greatly from device to device, so a solution that works with one may not work with another.
 
Upvote 0

Angelo2016

Member
Licensed User
Longtime User
Hi I found this code fragment where it has the function of sending text to google assistant..but I don't know how to insert it who can help me?THANKS
Activate assistant:
Dim intent1 As Intent
    intent1.Initialize("android.intent.action.VOICE_COMMAND", "")
    StartActivity(intent1)
    Try
        StartActivity(intent1)
    Catch
        Log(LastException)
    End Try


Query to assistant JAVA:
AssistConfig config = AssistConfig.newBuilder()
    .setTextQuery("Your text query goes here!")
    //.setAudioInConfig(audioInConfig)
    .setAudioOutConfig(audioOutConfig)
    .setDeviceConfig(deviceConfig)
    .setDialogStateIn(dialogStateIn)
    .setScreenOutConfig(screenOutConfig)
    .build();
AssistRequest request = AssistRequest.newBuilder().setConfig(config).build();

query to Google Assistant
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
In 2015, Erel gave an example of using the Google assistant. Even then everything was not so clear what was (im)possible.
Now we all know that Google changes a lot of things over time. If you start now because you can get a working example working eight years later, you will at least know whether you can get the Google Assistant working at all.

Suppose it works, then the question is whether you can make the working example work in an adapted version as you want (in 2015 it was not clear what exactly you could achieve with it). A program snipped is not sufficient to help you with this question.
 
Upvote 0
Top