在这个代码中,当我按下按钮(map(时,我打电话给谷歌助理 如何让它直接搜索最近的医院? 即我想直接使用我的代码搜索(医院附近(。 有什么方法可以用来执行谷歌助理的特定查询吗? 有吗。。如何使用它?
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button Map;
String Text;
protected static final int RESULT_SPEECH = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Map = (Button) findViewById(R.id.Map);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Map.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Google_Assistant();
}
});
}
public void Google_Assistant(){
Intent intent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
intent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
try {
startActivityForResult(intent, RESULT_SPEECH);
Text=("");
} catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(getApplicationContext(), "Unfortunately, this device does not support talk",
Toast.LENGTH_SHORT);
t.show();
}
}}
试试这个
String query = "nearby hospitals";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
intent.putExtra(SearchManager.QUERY, query);
startActivity(intent);