Can I sned Voice or Text Commands to Google Assistant to execute Commands?
I am using this Code now but it's open Normal Google Search Not Google Assistant.
String command = "hey google , open camera";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setClassName("com.google.android.googlequicksearchbox", "com.google.android.googlequicksearchbox.SearchActivity");
intent.putExtra("query", command);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //necessary if launching from Service
startActivity(intent);
The work around I did was
1 - launch the Assistant with voice command intent
Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
2 - read the command with a TextToSpeach engine
first define the TTS variable outside the oncreate function
private TextToSpeech mTTS;
then run this
mTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status==TextToSpeech.SUCCESS) {
mTTS.setLanguage(Locale.US);
mTTS.speak(" turn lights on ", TextToSpeech.QUEUE_FLUSH, null);
}
}
it worked like a charm
this is how you open the google assistant from your app, but actually it is not possible to to send a command to it.
Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.