简体   繁体   中英

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? 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? 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);

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.

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