Voice command that triggers a button in the Android app

Asked

Viewed 398 times

-1

I am beginner in Android and I made a structure for Speech to text, I would like to know how to trigger a button inside the application using this function.

1 answer

0

Hello, can you capture the right text yet? if not yet this tutorial exemplifies everything: http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/

if you implemented similarly within the onActivityResult method just compare the return of the voice with the action and call the Runnable that was linked to the button.

EDITION

public class MainActivity extends Activity {
    private Button botaoAcao;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        botaoAcao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                acaoDoBotao().run();
            }
        });
    }

    private Runnable acaoDoBotao() {


        return new Runnable() {
            @Override
            public void run() {
                //acao do botao
            }
        };
    }

And inside the onActivityResult to call the boot just call the acaoDoBotao().run();

  • I can capture the text yes and turn it into a string , what I get complicated is just how I call the button

  • got it... I will edit in the above answer an example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.