在应用程序中添加以下代码以启用Google Assistant的语音命令:
接着,添加以下代码以处理Intent:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
if (Intent.ACTION_VIEW.equals(action) && data != null) {
String path = data.getPath();
if ("/open".equals(path)) {
// 启动应用程序的代码
}
}
}
此代码将允许用户使用以下谷歌助理语音命令启动应用程序:
“嘿Google,在example.com上打开应用程序”或“嘿Google,打开应用程序”