RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS in Oreo

On most Android devices, RecognitionService will ship using the Google Now / Assistant native application.

Prior to Android Oreo, I was able to query the languages ​​supported by Google Recognizer using the following simple code:

final Intent vrIntent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS); // vrIntent.setPackage("com.google.android.googlequicksearchbox"); getContext().sendOrderedBroadcast(vrIntent, null, new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { // final Bundle bundle = intent.getExtras(); final Bundle bundle = getResultExtras(true); if (bundle != null) { if (bundle.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) { Log.i("TAG", "onReceive: EXTRA_SUPPORTED_LANGUAGES present"); final ArrayList<String> vrStringLocales = bundle.getStringArrayList( RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES); Log.i("TAG", "onReceive: EXTRA_SUPPORTED_LANGUAGES size: " + vrStringLocales.size()); } else { Log.w("TAG", "onReceive: missing EXTRA_SUPPORTED_LANGUAGES"); } } else { Log.w("TAG", "onReceive: Bundle null"); } }, null, 1234, null, null); 

However, since 8.0+ the additional RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES no longer contained in the response.

Before I try to write this down as an error, I wanted to first see if others could replicate, but also check if there was an ordered translation of a behavioral change in API 26. I somehow lost sight of what might be causing this.

Thanks in advance.

+9
java android speech-recognition voice-recognition google-voice-search
source share
1 answer

So, I could not replicate, but in addition to the comments, if you do not set the package name

 vrIntent.setPackage("com.google.android.googlequicksearchbox"); 

then it fails, otherwise everything works fine for me.

This is the main work that I used to test it.

 package it.versionestabile.stackover001; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.speech.RecognizerIntent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import java.util.ArrayList; import static java.security.AccessController.getContext; /** * https://stackoverflow.com/questions/48500077/recognizerintent-action-get-language-details-in-oreo */ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Intent vrIntent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS); vrIntent.setPackage("com.google.android.googlequicksearchbox"); PackageManager packageManager = getPackageManager(); for (PackageInfo packageInfo: packageManager.getInstalledPackages(0)) { if (packageInfo.packageName.contains("com.google.android.googlequicksearchbox")) Log.d("AAA", packageInfo.packageName + ", " + packageInfo.versionName); } this.sendOrderedBroadcast(vrIntent, null, new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { // final Bundle bundle = intent.getExtras(); final Bundle bundle = getResultExtras(true); if (bundle != null) { if (bundle.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) { Log.i("TAG", "onReceive: EXTRA_SUPPORTED_LANGUAGES present"); final ArrayList<String> vrStringLocales = bundle.getStringArrayList( RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES); Log.i("TAG", "onReceive: EXTRA_SUPPORTED_LANGUAGES size: " + vrStringLocales.size()); } else { Log.w("TAG", "onReceive: missing EXTRA_SUPPORTED_LANGUAGES"); } } else { Log.w("TAG", "onReceive: Bundle null"); } } }, null, 1234, null, null); } } 

I tested it both on Android Studio 2.3 and 3.0.1, and on an emulator with APIs 26 and 27.

Everything works fine with the above code.

But if you comment out this line:

 vrIntent.setPackage("com.google.android.googlequicksearchbox"); 

on Oreo it does not work.

And still I suggest checking Google Now with the package manager in a way like this:

PackageManager packageManager = getPackageManager ();

 for (PackageInfo packageInfo: packageManager.getInstalledPackages(0)) { if (packageInfo.packageName.contains("com.google.android.googlequicksearchbox")) Log.d("AAA", packageInfo.packageName + ", " + packageInfo.versionName); // TODO - set a boolean value to discriminate the precence of google now } 

To decide if you have the right version of Google Now.

Hope this helps!

+5
source share

All Articles