Sending commands to Google Assistant from Android

2020-02-14 10:51发布

In order to increase efficiency I want to send frequently used commands to Google Assistant from an Android app via script. E.g. "Ok, Google .

This is the code I use for calling Assistant from a Service:

startActivity(new Intent(Intent.ACTION_VOICE_COMMAND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

I have found this topic, which says that this is not possible for Raspberry Pi which uses Google Assistant SDK. Is it the same for Android apps?

1条回答
Summer. ? 凉城
2楼-- · 2020-02-14 11:06

Managed to make it work:

String command = "navigate home by public transport";
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
context.startActivity(intent);

Source: StackOverflow question

查看更多
登录 后发表回答