简体   繁体   English

如何在 Google Assistant 中直接调用 map?

[英]How to call the map in Google Assistant directly?

In this code, I called Google Assistant when I pressed the button(map) How can I make it do a direct search for the nearest hospital?在这段代码中,当我按下按钮(地图)时,我调用了 Google Assistant 我怎样才能让它直接搜索最近的医院? ie I want to search on (near hospital ) directly using my code.即我想直接使用我的代码搜索(靠近医院)。 is there method I can use to execute specific query for Google Assistant?有什么方法可以用来执行 Google Assistant 的特定查询吗? is there.. how can I use it?有没有..我该如何使用它?

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();
        }
    }}

Try this尝试这个

String query = "nearby hospitals";
                        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
                        intent.putExtra(SearchManager.QUERY, query);
                        startActivity(intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM