简体   繁体   English

扩展Android的语音搜索应用

[英]Extending Android's Voice Search app

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 voice search app that launches automatically when you long press the physical "search" key. 我知道我可以在我自己的应用程序中添加一个按钮来启动语音识别对话框,但我想知道是否可以扩展在长按物理“搜索”键时自动启动的语音搜索应用程序。

send text to [contact] [message]
listen to [artist/song/album]
call [business]
call [contact]
send email to [contact] [message]
go to [website]
note to self [note]
navigate to [location/business name]
directions to [location/business name]
map of [location]

I'd basically like to add my own action to the above list. 我基本上想将自己的动作添加到上面的列表中。

Is this possible or will I have to create my own? 这是可能的还是我必须创建自己的?

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. 您必须完全编写自己的应用程序,这是其他人所做的事情。

A simple method to Handle Voice Search 处理语音搜索的简单方法

Step 1 Call this method on button click 步骤1单击按钮调用此方法

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 步骤2覆盖onActivityResult方法

@ 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 多数民众赞成

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

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