所以我試圖開發一種使用語音識別處理很多的事件就像調用任何一個電話號碼的應用程序,打開其他應用程序,切換設置等使用語音命令在android中打開另一個應用程序?
我所做的到現在正在實施的呼叫特性,我在哪裏卡住的地方是如何打開另一個應用程序
我的代碼到目前爲止是:
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":
}
}
}
}
}
現在,你可以看到,我可以使用情況下,「開放」作爲第一個字,然後用它繼續。但我不知道如何獲取手機上當前安裝的所有應用程序的列表。 請幫忙?
'ResolveInfo {151f1374 com.snapchat.android/.LandingPageActivity m = 0x108000}'。 List packageAppsList包含各種元組,如上面所引用的元組。我應該如何從這些信息中提取應用程序名稱。非常感謝。 –
@XavierJacob查看我的編輯 – sup4eli
非常感謝您的編輯。它完美地解決了我的問題。 –