Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically get current keyboard language on an Android device

I am writing an application which is using dictionaries. I want to switch between dictionaries any time user change input language. For example if the typing language is english work with english dictionary, if it is german, work with german dictionary. Is there any way to set a listener to get that change? All the answer i found were about locale and not about input language. I don't want to handle locale, locale has no effect in application, the input language does. (I am developing in minSDK=7)

like image 283
Christos Asa Avatar asked May 10 '13 13:05

Christos Asa


2 Answers

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();

String locale = ims.getLocale();

You can try this code to get Current Keyboard Language regional code.

like image 115
Ramkailash Avatar answered Nov 17 '22 23:11

Ramkailash


It is possible

imm.getCurrentInputMethodSubtype();

to return you null value. In this case you should check language of android system like this

Locale.getDefault().getLanguage()        ---> en     

otherwise you will receive NullPointerException

like image 2
Stoycho Andreev Avatar answered Nov 18 '22 00:11

Stoycho Andreev