使用语音命令打开 android 中的另一个应用程序?

Open another application in android using voice commands?

所以我正在尝试开发一个使用语音识别来处理许多事件的应用程序,例如拨打任何 phone 号码、打开其他应用程序、切换设置等。

我目前所做的就是实现调用功能,卡住的地方是如何打开另一个应用程序

我现在的代码是:

private void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech Prompt");
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(), "Error Occured Try again",Toast.LENGTH_SHORT ).show();
    }
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode,resultCode,data);

    switch(requestCode) {
        case REQ_CODE_SPEECH_INPUT : {
            if (resultCode == RESULT_OK && null != data) {
                ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                txtSpeechInput.setText(result.get(0));
                String arr[] = result.get(0).split(" ",2);
                String firstWord = arr[0];
                String secondWord = arr[1];
                switch(firstWord) {
                    case "call":
                        callPhone(secondWord);
                        break;
                    case "open":


                }

            }
        }
    }
}

现在如您所见,我可以使用 case "open" 作为第一个单词,然后继续使用它。但我不知道如何获取 phone 当前安装的所有应用程序的列表。 请帮忙?

相关问题:

从那里引用:"As far as I am aware, Google simply iterates over a list of installed applications and opens the corresponding application if it finds an exact match."

此致,

获取设备上所有 application/activities 安装的列表:

final Intent Intent = new Intent(Intent.ACTION_MAIN, null);
Intent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> packageAppsList = context.getPackageManager().queryIntentActivities(Intent, 0);

获取相关数据以打开 ResolveInfo 上的应用程序,阅读以下内容:

for (ResolveInfo res : packageAppsList ){
    //print it to logger etc.
    res.loadLabel(getPackageManager().toString();

https://developer.android.com/reference/android/content/pm/ResolveInfo.html