A call to android.speech.RecognizerIntent API leads to the Connection Error dialog, shows a warning "call_package" in the log

I wrote a small application so that the user can choose in which language he uses Voice Search by pressing a button, instead of relying on the user's preferences (sometimes you want the voice to be in Japanese, without switching the entire user interface to Japanese).

I am testing the application on my HTC Desire / Android 2.1 (Softbank-x06ht). However, when I call the api voice, I get the “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

Please note that I can use the Google Voice Search application and it works without problems.

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

I tried to provide the parameter myself, but it did not change the result 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());
    }
}
+3
source share
2 answers

I had the same problem and I put the calling package in the actual calling package (not the class), and then everything worked correctly. Android 2.2 on the Tmobile G2.

+1
source

Use this code to get the name of your package.

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                context.getPackageName());
+2
source

Source: https://habr.com/ru/post/1764341/


All Articles