奥利奥的RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS
2022-09-04 02:58:22
在大多数Android设备中,RecognitionService将由Google的本机“Now/Assistant”应用程序提供。
在Android Oreo之前,我能够使用以下简单代码查询Google识别器支持的语言:
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);
但是,由于8.0 +,响应中不再包含额外的内容。RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES
在我尝试将其作为错误提交之前,我想首先看看其他人是否可以复制 - 但也要检查API 26中是否有我以某种方式忽略的有序广播行为更改,这可能是导致这种情况的原因。
提前致谢。