2012-02-28 55 views
5

的異常被拋出下面的代碼:無活動處理意向{行動= android.speech.action.RECOGNIZE_SPEECH(有演員)}

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
     RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); 
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);. 

我GOOGLE了,發現這是因爲來自google的the voice search app在我正在使用的設備上缺失。我可以通過手動安裝應用程序來解決問題,但是我怎樣才能安裝apk程序,比如導入一些庫或其他文件〜
非常感謝。

回答

5

打開的應用程序(您想使用)在Web視圖鏈接

try{ 
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
     RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); 
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);. 
} 
catch(ActivityNotFoundException e) 
{ 
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://market.android.com/details?id=APP_PACKAGE_NAME")); 
startActivity(browserIntent); 

} 

與語音rcognition應用A包名市場

+0

感謝您的回覆vipin,但我可以添加語音模塊作爲我的apk的一部分。 – Bolton 2012-02-28 13:32:24

+0

是的,你可以肯定 ,但爲此你必須自己寫下整個代碼 – vipin 2012-02-28 13:34:41

+0

@vipin當你說APP_PACKAGE_NAME時,你知道哪些是默認的?我的意思是它可以在我的其他設備上正常工作,但對於Sony Experia Mini,語音識別不起作用。所以我想指出用戶來自Google的默認語音識別。 – 2012-06-29 17:29:57

1

VIPIN的解決方案取代APP_PACKAGE_NAME在https://market.android.com/details?id=APP_PACKAGE_NAME作品。 我個人用這個作爲我APP_PACKAGE_NAME: com.google.android.googlequicksearchbox

所以要回顧一下完整的解決方案,你會做以下幾點:(我修改了一些以先行先試的方案,然後在https://後備如果失敗。 )

try { 
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
     RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); 
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);. 
} catch(ActivityNotFoundException e) { 
    String appPackageName = "com.google.android.googlequicksearchbox"; 
    try { 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); 
    } catch (android.content.ActivityNotFoundException anfe) { 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); 
    } 
} 
相關問題