Reputation: 2484
How can we check selected language support on the Android device? or How to get currently supported language in Android device
Upvotes: 2
Views: 661
Reputation: 2484
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")
Upvotes: 5
Reputation: 857
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)
Upvotes: 2