It is possible to determine via code which language packages are currently installed on a device? Tried this:
Intent detailsIntent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
sendOrderedBroadcast(detailsIntent, null, new LanguageDetailsChecker(), null, Activity.RESULT_OK, null, null);
public class LanguageDetailsChecker extends BroadcastReceiver {
private List<String> supportedLanguages;
@Override
public void onReceive(Context context, Intent intent)
{
Bundle results = getResultExtras(true);
if (results.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES))
{
supportedLanguages =results.getStringArrayList(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
Log.d("TAG","languages: " + supportedLanguages);
}
}
}
However, the output shows me tons of languages, while I only have en_UK, en_US and es_ES installed. Any idea?
If you have root(sorry), you can do it this way:
public static boolean isOfflineDictionaryPresent(String language) {
if (locale == null) locale = Locale.US;
String dir = "/system/usr/srec/config/" +
language.replace('_', '.').toLowerCase();
if ((new File(dir)).isDirectory()) return true;
return false;
}
This was ripped from the Android 4.2.2 Recognizer.java source and modified:
I'd get the full list just as you are, and loop through them to check which ones are available offline. I've checked the /system/usr/srec/config/
folder on two devices, and they both match the dictionaries I have installed.
Of course, the down side is that it only works for root, so I'm not sure how helpful this will be to you in the end. I'm really not sure what to say for non-root, I can't find anything.
Edit: Out of curiosity, though, what does EXTRA_SUPPORTED_LANGUAGES contain if you are offline? If it returns correctly, you might just have to fake out the network manager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With