从活动pinstalled应用程序启动$ P $(谷歌语音搜索)的Andr​​oid [英] Launch Preinstalled App from activity (Google Voice Search) Android

查看:607
本文介绍了从活动pinstalled应用程序启动$ P $(谷歌语音搜索)的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用下面的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 $(谷歌语音搜索)的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆