代码之家  ›  专栏  ›  技术社区  ›  Brandon O'Rourke

扩展Android的语音搜索应用程序

  •  10
  • Brandon O'Rourke  · 技术社区  · 14 年前

    是否可以扩展语音搜索应用程序?我知道我可以在自己的应用程序中添加一个按钮来启动语音识别对话框,但我想知道是否可以扩展当你长按物理“搜索”键时自动启动的语音搜索应用程序。

    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]
    

    我基本上想把我自己的行为添加到上面的列表中。

    这是可能的,还是我必须创建自己的?

    2 回复  |  直到 7 年前
        1
  •  2
  •   Rohan Singh    14 年前

    总之,没有。这个应用程序没有你想要的扩展点。你必须完全编写自己的应用程序,这是别人做的。

        2
  •  0
  •   shivampip    7 年前

    一个简单的方法 处理语音搜索

    步骤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);
    }
    

    步骤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);
        }
    }
    

    这一切,完成了