7

I develop an sms sender app and I wanna know language that user uses. so, when user types a message how can I know language that he/she uses?

NrNazifi
  • 1,621
  • 3
  • 25
  • 36
  • 1
    http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#getCurrentInputMethodSubtype%28%29 – hakki Feb 08 '13 at 14:56

3 Answers3

10

get the input type manager by using:

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

then , choose what to get from it using the next methods :

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#getCurrentInputMethodSubtype%28%29

or: http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#getLastInputMethodSubtype()

together with this to get the locale of the input type:

http://developer.android.com/reference/android/view/inputmethod/InputMethodSubtype.html#getLocale()

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • 1
    hi guy, but this solution available in API 11, and I want to use that for android 2.3! how to use your idea for lower versions before API 11. – NrNazifi Feb 12 '13 at 07:37
  • good point. sorry for missing it . maybe it's possible to read from the android code and see if there is a way to overcome it for older versions . – android developer Feb 12 '13 at 09:33
  • Google keyboard does not return language code.. what to do about that? any solution? – axita.savani Mar 02 '22 at 12:39
4

You can get keyboard language by first detecting the locale of device keyboard and then getting the Locale object from it. For example,

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
    String localeString = ims.getLocale();
    Locale locale = new Locale(localeString);
    String currentLanguage = locale.getDisplayLanguage();

Here, currentLanguage will give your keyboard language. Hope this helps.

AndyN
  • 1,742
  • 1
  • 15
  • 30
0

It's impossible to retrieve the current keyboard language. Android does not allow to retrieve the current configured language, there aren't any API.

StarsSky
  • 6,721
  • 6
  • 38
  • 63