0

Can I read the languages that an android device supports? I know we can read the current language, but I want to read all the languages.

Afaik, it's there in System/Fonts. But can I access it without rooting the device?

EDIT: I tried Locale on a Moto-G and it the list contains Gujarati language, that seems to be because v. 5.0.2 supports the language, but the device does not support the Gujarati font. Need to know what fonts are supported on a particular device, so that I can decide whether to render them.

codemonger
  • 47
  • 8
  • 1
    `Afaik, it's there in System/Fonts` Fonts have **nothing** to do with languages. They only provide graphical representation for the characters. – Phantômaxx Aug 03 '15 at 08:10
  • 1
    possible duplicate of [How to find supporting languages in android programatically?](http://stackoverflow.com/questions/12406878/how-to-find-supporting-languages-in-android-programatically) – Phantômaxx Aug 03 '15 at 08:12
  • 1
    possible duplicate of [What is the list of supported languages/locales on Android?](http://stackoverflow.com/questions/7973023/what-is-the-list-of-supported-languages-locales-on-android) – IngoAlbers Aug 03 '15 at 08:16
  • @EgonWilzer please check the edit and suggest if you have a solution. TIA! :) – codemonger Aug 03 '15 at 09:48
  • @DerGol...lum That's what I think is the problem, the fonts for certain languages aren't available hence I can't render them. – codemonger Aug 03 '15 at 10:05
  • 1
    This means that certain fonts don't provide the required graphics (Unicode characters). Then simply provide the fonts for the specific (natively unsupported) languages, such as Myanmar.ttf (just to name some one I can remember some user asked for). – Phantômaxx Aug 03 '15 at 10:27
  • @DerGol...lum That requires the device to be rooted, which I can't. Instead if I can just know if the font is not supported and eliminate its rendering? – codemonger Aug 03 '15 at 10:42
  • 1
    `That requires the device to be rooted` NO, it doesn't. Just provide your fonts in your app `assets` folder. See this: http://stackoverflow.com/questions/3651086/android-using-custom-font – Phantômaxx Aug 03 '15 at 11:31

1 Answers1

0

This worked for me!

public void checkSupportedFonts() {

    mLanguageFonts = new HashMap<String, String>();

    mLanguageFonts.put("en-US", "ab");
    mLanguageFonts.put("hi-IN", "अआ");
    mLanguageFonts.put("bn-IN", "অআ");
    mLanguageFonts.put("gu-IN", "અઆ");
    mLanguageFonts.put("mr-IN", "अआ");
    mLanguageFonts.put("ta-IN", "அஆ");
    mLanguageFonts.put("te-IN", "అఆ");
    mLanguageFonts.put("kn-IN", "ಅಆ");
    mLanguageFonts.put("ml-IN", "അആ");

    Iterator<Entry<String, String>> languageIterator = mLanguageFonts.entrySet().iterator();
    while (languageIterator.hasNext()) {
        Map.Entry<String, String> pair = (Entry<String, String>)languageIterator.next();
        String font = pair.getValue().toString();

        if(isSupported(font))
            Log.d(TAG, "language is supported : " + pair.getKey());
        else
            Log.d(TAG, "language is unsupported : " + pair.getKey());
        }
}

private boolean isSupported(String text) 
{

    String char1 = text.substring(0, 1);
    text = text.substring(1, 2);
    Bitmap bitmap1 = generateBitmap(context, char1);
    Bitmap bitmap2 = generateBitmap(context, text);
    boolean res = !bitmap1.sameAs(bitmap2);
    bitmap1.recycle();
    bitmap2.recycle();
    return res;
}
codemonger
  • 47
  • 8