2016-03-03 76 views
0

Locale.getAvaialableLocales()爲您提供設備中可用的所有語言環境。 但設備安裝字體只支持其中的一些可用語言如何檢查特定語言是由設備支持的android

我用Resources.getSystem().getAssets().getLocales() 它返回「設置 - >語言&輸入 - >語言」可用列表語言選項。

但該設備能夠支持未在存在更多的語言「設置 - >語言&輸入 - >語言」也。

例如 在我的Karbon設備中,Resources.getSystem()。getAssets()。getLocales()僅返回 作爲支持語言的「印地語」和「旁遮普語」。 但是,使用「遠足」應用程序選擇「泰盧固語」時,本設備工作正常。

那麼有沒有什麼方法可以檢查設備是否支持特定的語言。

回答

3

好問題Siva。

到目前爲止,很多人一直在討論這個相同的事情,最終沒有答案。

google groups discussion is here

無論Locale.getAvailableLocales() 也不Resources.getSystem().getAssets().getLocales() 爲您提供了正確的設置,你可以依靠支持應用程序的語言環境中。

原因是,

他們都爲您提供了由操作系統支持的所有語言環境的列表。操作系統可能支持超過100種語言,但設備製造商可能不會將所有這些語言字體(ttf文件)放在/ system/fonts /(或任何系統字體目錄)中以保存ROM內存。他們所做的是,由於他們製作區域特定的ROM,他們只放置與該特定區域相關的字體(區域設置)。這就是你在美國ROM中找不到印度區域語言的原因。

解決它的最好辦法, 包括在任何語言要支持你的應用程序的所有資產的ttf文件, 就像我們給出了不同的語言字符串的支持。

但照顧字體許可和所有。

希望這會有所幫助。

0

我已經做了以下的方法:

調用方法是這樣的:

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; 
    } 

希望它會幫助你!