从活动pinstalled应用程序启动$ P $(谷歌语音搜索)的Android [英] Launch Preinstalled App from activity (Google Voice Search) Android
问题描述
我尝试使用下面的code,从我的应用程序推出谷歌语音搜索。它工作正常,在Nexus One上,其中谷歌语音搜索是一个下载的应用程序,但它不会对我的Galaxy Nexus的工作,它是从哪里来的preinstalled。当它到达getLaunchIntentForPackage,则结果为NULL。谁能帮帮忙?
意向书我=新的意图(Intent.ACTION_MAIN);
PackageManager经理= getPackageManager();
尝试 {
I = manager.getLaunchIntentForPackage(com.google.android.voicesearch);
}赶上(的NameNotFoundException E){
// TODO自动生成的catch块
e.printStackTrace();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(ⅰ);
我遇到了相同问题。这似乎是由方式谷歌已经打包在ICS中的语音分量而引起的。这不是一个独立的应用程序了。它集成到通过通用搜索应用程序的搜索栏。
解决方法是很容易的:
意向意图=新的意图(RecognizerIntent.ACTION_WEB_SEARCH);
startActivity(意向);
我发现这个通过本教程,更多的是一般的语音识别: <一href="http://www.jameselsey.co.uk/blogs/techblog/android-how-to-implement-voice-recognition-a-nice-easy-tutorial/">http://www.jameselsey.co.uk/blogs/techblog/android-how-to-implement-voice-recognition-a-nice-easy-tutorial/
有一些code在那里,以验证该声音识别器安装:
PackageManager PM = getPackageManager();
名单&LT; ResolveInfo&GT;活动= pm.queryIntentActivities(
新意图(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),0);
如果(activities.size()== 0)
{
speakButton.setEnabled(假);
speakButton.setText(识别器不是present);
}
I am trying to use the following code to launch Google Voice Search from my app. It works fine on the Nexus One where Google Voice Search is a downloaded App, however it does not work on my Galaxy Nexus where it comes preinstalled. when it gets to the getLaunchIntentForPackage, the result is NULL. Can anyone help out?
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.google.android.voicesearch");
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
I ran into the exact same problem. It seems to be caused by the way google has packaged up the voice component in ICS. It's not a standalone app anymore. It's integrated into the search bar through the general search app.
The fix is really easy:
Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
startActivity(intent);
I found this through this tutorial that's more about general speech recognition: http://www.jameselsey.co.uk/blogs/techblog/android-how-to-implement-voice-recognition-a-nice-easy-tutorial/
There's some code in there to verify that the voice recognizer is installed:
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() == 0)
{
speakButton.setEnabled(false);
speakButton.setText("Recognizer not present");
}
这篇关于从活动pinstalled应用程序启动$ P $(谷歌语音搜索)的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!