armia
armia

Reputation: 25

Detect Android language support

I have developed application in Arabic language, And I want to support a wild rang of Android Devices. I want to detect if the device support Arabic to load it in Arabic or to load in English.

Upvotes: 2

Views: 1366

Answers (3)

Lalit Jadav
Lalit Jadav

Reputation: 1427

You can use this method to check particular language support

if (isSupported(baseContext, "हिन्दी"))
    languageList.add("हिन्दी")

Just replace हिन्दी with arabic word

public static boolean isSupported(Context context, String text) {
        int w = 200, h = 80;

        Resources resources = context.getResources();
        float scale = resources.getDisplayMetrics().density;
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
        Bitmap orig = bitmap.copy(conf, false);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.rgb(0, 0, 0));
        paint.setTextSize((int) (14 * scale));

        // draw text to the Canvas center
        Rect bounds = new Rect();
        paint.getTextBounds(text, 0, text.length(), bounds);
        int x = (bitmap.getWidth() - bounds.width()) / 2;
        int y = (bitmap.getHeight() + bounds.height()) / 2;

        canvas.drawText(text, x, y, paint);
        boolean res = !orig.sameAs(bitmap);
        orig.recycle();
        bitmap.recycle();
        return res;
}

Refer full

Upvotes: 0

Pedantic
Pedantic

Reputation: 5022

If you just need to check the configured locale you can use <context>.getResources().getConfiguration().locale (is a java.util.Locale).

If you want to display the appropriate language resources based on the user's locale, the framework easily permits this. You add your string.xml files to appropriate resource folders as documented in this d.android.com article and the OS will use the appropriate one.

Upvotes: 1

Emmanuel N
Emmanuel N

Reputation: 7449

Use getAvailableLocales() to get a list of available languages

Upvotes: 0

Related Questions