How can we check selected language support on the Android device? or How to get currently supported language in Android device
Asked
Active
Viewed 645 times
2 Answers
5
I have created one method for checking particular language supported or not.
public static boolean isLanSupported(Context context, String text) {
final int WIDTH_PX = 200;
final int HEIGHT_PX = 80;
int w = WIDTH_PX, h = HEIGHT_PX;
Resources resources = context.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bitmap = Bitmap.createBitmap(w, h, conf);
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
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;
}
following way to call a method
isLanSupported(getActivity(),"ગુજરાતી")
isLanSupported(getActivity(),"हिंदी")
isLanSupported(getActivity(),"English")

Sanjay Bhalani
- 2,424
- 18
- 44
-
Not sure how this works! If "ગુજરાતી" is not supported `bitmap` will have some garbage value. It is never same as `orig` – Arka Prava Basu May 17 '19 at 12:14
2
You can get the default language with de Locale object
Locale.getDefault() for the default, and Locale.getAvailableLocales() for available langages. (See this other post)

J-Jamet
- 847
- 8
- 17
-
1Thank you J-Jamet for your answer, but it will not work for all language. For example In Nexus device Locale.getAvailableLocales() OR Resources.getSystem().getAssets().getLocales() returns only "Hindi" and "Punjabi" as supporting languages. But this device works fine when select "Gujarati" language in any application. – Sanjay Bhalani Jul 11 '17 at 13:15
-
2Indeed, there are languages that are not officially supported on older versions of the API. Gujarati must have fonts to integrate as root to work. XDA Post : https://forum.xda-developers.com/showthread.php?t=2429440 and https://stackoverflow.com/questions/22111764/android-gujrati-and-hindi-supported-application So sorry for this but you have more work to do for this language. – J-Jamet Jul 11 '17 at 17:31