Extending Android's Voice Search app

前端 未结 2 1979
旧巷少年郎
旧巷少年郎 2020-12-31 11:39

Is it possible to extend the Voice Search app? I know I can add a button in my own app to launch the voice recognition dialog, but I was wondering if I could extend the voi

相关标签:
2条回答
  • 2020-12-31 12:37

    In a word, no. The app doesn't have the extension points you are looking for. You would have to write your own app entirely, which is something that others have done.

    0 讨论(0)
  • 2020-12-31 12:37

    A simple method to Handle Voice Search

    Step 1 Call this method on button click

    public void startVoiceRecognition() {
        Intent intent = new Intent("android.speech.action.RECOGNIZE_SPEECH");
        intent.putExtra("android.speech.extra.LANGUAGE_MODEL", "free_form");
        intent.putExtra("android.speech.extra.PROMPT", "Speak Now");
        this.mContainerActivity.startActivityForResult(intent, 3012);
    }
    

    Step 2 Override onActivityResult method

    @ Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 3012 && resultCode == RESULT_OK) {
            ArrayList < String > matches = data.getStringArrayListExtra("android.speech.extra.RESULTS");
            String result= matches.get(0);
            //Consume result 
            edittext.setText(result);
        }
    }
    

    Thats all, DONE

    0 讨论(0)
提交回复
热议问题