0

I saw many posts about this subject but none of them worked.

I have an EditText that is used latter to perform a query.

It is important for me to know wether the language is English or Hebrew.

I haev tried many solutions such as:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
String locale = ims.getLocale();

where returns "".

Also tried to use Locale but it returns the language of the device and not the language of the current keyboard.

Is there any way to do it instead of checking each letter?

if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
  //english letter
}

Thank you

Ben
  • 1,737
  • 2
  • 30
  • 61
  • 1
    "Is there any way to do it instead of checking each letter?" -- no. After all, the user could change languages per character, using as many languages as the user wants (including languages that are neither English nor Hebrew). The user could also enter emoji. – CommonsWare Nov 01 '20 at 18:39

1 Answers1

0

The only way to make 100% sure what Locale the inputted text is, is by checking every letter. There is no restrction what Locale the user is typing in, or if the user even had the language you want in their Locales.

P.S : Sadly Android does not have any API to restrict Locale, it is on iOS though, so hopefully one day it will arrive to Android

Ahmad Sattout
  • 2,248
  • 1
  • 19
  • 42