如何检查特定语言是由设备支持的android
Locale.getAvaialableLocales()
为您提供设备中可用的所有语言环境。 但设备安装字体只支持其中的一些可用语言如何检查特定语言是由设备支持的android
我用Resources.getSystem().getAssets().getLocales()
它返回“设置 - >语言&输入 - >语言”可用列表语言选项。
但该设备能够支持未在存在更多的语言“设置 - >语言&输入 - >语言”也。
例如 在我的Karbon设备中,Resources.getSystem()。getAssets()。getLocales()仅返回 作为支持语言的“印地语”和“旁遮普语”。 但是,使用“远足”应用程序选择“泰卢固语”时,本设备工作正常。
那么有没有什么方法可以检查设备是否支持特定的语言。
好问题Siva。
到目前为止,很多人一直在讨论这个相同的事情,最终没有答案。
google groups discussion is here
无论Locale.getAvailableLocales()
也不Resources.getSystem().getAssets().getLocales()
为您提供了正确的设置,你可以依靠支持应用程序的语言环境中。
原因是,
他们都为您提供了由操作系统支持的所有语言环境的列表。操作系统可能支持超过100种语言,但设备制造商可能不会将所有这些语言字体(ttf文件)放在/ system/fonts /(或任何系统字体目录)中以保存ROM内存。他们所做的是,由于他们制作区域特定的ROM,他们只放置与该特定区域相关的字体(区域设置)。这就是你在美国ROM中找不到印度区域语言的原因。
解决它的最好办法, 包括在任何语言要支持你的应用程序的所有资产的ttf文件, 就像我们给出了不同的语言字符串的支持。
但照顾字体许可和所有。
希望这会有所帮助。
我已经做了以下的方法:
调用方法是这样的:
isSupported(context,"English") //here "English" is the hardcoded string in specific language like Hindi,Urdu,panjabi .....etc.
是否支持,如果设备有能力吸引其他特定语言字体明智返回false方法将返回true。
public static boolean isSupported(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); // 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;
}
希望它会帮助你!