Calling android.speech.RecognizerIntent API results in Connection Error dialog, shows 'calling_package' warning in log

拈花ヽ惹草 提交于 2020-01-04 04:22:06

问题


I wrote a small app to allow the user to choose which language he uses the Voice Search via a button, rather than relying on the user's language preference (sometimes you want to voice search in Japanese without switching your whole UI to Japanese).

I am testing the app on my HTC Desire /Android 2.1 (Softbank-x06ht). However, when I call the voice api, I get a "Connection Failed" dialog box [retry/cancel], and LogCat shows this warning:

09-12 11:26:13.583: INFO/RecognitionService(545): ssfe url=http://www.google.com/m/voice-search
09-12 10:49:45.683: WARN/RecognitionService(545): required parameter 'calling_package' is missing in IntentAPI request

Note that I can use the Google Voice Search app and it works with no problems.

According to the API Docs http://developer.android.com/reference/android/speech/RecognizerIntent.html#EXTRA_CALLING_PACKAGE the calling_package parameter is not to be used by developers. Well, if that is the case, why does the log say it is missing?

I tried to provide the parameter myself but it didnt change the outcome at all.

 private static final String TRIVOICE_CALLING_PACKAGE = "calling_package";
 private void callSpeechWebSearch (String language) {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,
            language);
    intent.putExtra(TRIVOICE_CALLING_PACKAGE,
            "org.filsa.trivoice");

    //intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    try {
        startActivity(intent);         
    } catch (ActivityNotFoundException anfe) {
     makeToast("ANFE:" +anfe.getMessage());
    }
}

回答1:


I was having the same problem and set the calling package to the actual calling package (not class) and things then worked correctly. Android 2.2 on a Tmobile G2.




回答2:


Use this code to get your package name

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                context.getPackageName());


来源:https://stackoverflow.com/questions/3693480/calling-android-speech-recognizerintent-api-results-in-connection-error-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!