In most Android devices, the RecognitionService will be supplied by Google's native 'Now/Assistant' application.
Up until Android Oreo, I was able to query the languages supported by the Google Recognizer with 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 extra RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES
is no longer contained in the response.
Before I attempt to file this as a bug, I wanted to firstly see if others could replicate - but also check if there has been an Ordered Broadcast behavioural change in API 26 I've somehow overlooked, which could be the cause of this.
Thanks in advance.
So, I could't replicate, but further to the comments, if you don't set the package name
then it fails, otherwise all works fine to me.
That's the basic activity I've used to test it.
I've tested it both on Android Studio 2.3 and 3.0.1 and on emulator with API 26 and 27.
All works fine with the above code.
But if you comment out this line:
on Oreo it doesn't work.
And I still suggest to check the presence of Google Now with Package Manager in a way like this:
PackageManager packageManager = getPackageManager();
In order to decide if you have the right version of Google Now.
Hope it helps!