Android Tutorial How to disable keyboard suggestions

Discussion in 'Tutorials & Examples' started by Sandman, Jan 12, 2018.

Tags:
  1. Sandman

    Sandman Active Member Licensed User

    There are numerous threads in the forum about this, but I didn't have much luck with them. I wanted to disable the suggestions, but they always showed. I saw one suggestion setting the field to be for email, which disabled the suggestions - but that's clearly just a dirty workaround.

    This is the relevant documentation: android:inputType

    In the forum we can see the suggestion for code like this:
    Code:
    editText.InputType = Bit.Or(editText.InputType, 0x80000)
    and sometimes this:
    Code:
    editText.InputType = Bit.Or(editText.InputType, 0x80001)
    That code targets this flag:
    upload_2018-1-12_13-20-57.png
    (Note: The value displayed for this flag seems to have a typo. Clicking the blue link reveals that the flag actually has the value 0x80000.)

    Which seems reasonable. The problem is that it seems to not work.

    To remove suggestions it seems that two flags needs to be targeted. Both enabling the one above, and disabling this one:
    upload_2018-1-12_13-17-13.png

    Which means that to remove suggestions, this is a working solution:
    Code:
    editText.InputType = 0x80000
    Or, if you want to be a bit more correct, do the Bit.Or for 0x80000 and then Bit.And 0xFFFFE. (To remove the 1, if it was set.)

    IMPORTANT UPDATE:
    What I wrote above is not entirely correct. It was tested on a device using "Android Keyboard (AOSP)" on Android 6, and there it worked as expected. When I tried the same thing on another device (that ran same OS version as first one) it failed to disable the suggestions.

    After some investigation it seems that Gboard is the problem. Read this post at Stack Overflow for more information: Programmatically disable auto-suggestions on Gboard. (I can only assume that other keyboards also have quirks, I have not tried any more than these two though.)

    However, I have verified that 0x21 (textEmailAddress) works for all my devices. Which means we've come full circle to the dirty workaround mentioned initially. *sigh*
     
    Last edited: Jan 12, 2018
  2. panagiotisden2

    panagiotisden2 Member Licensed User

    the problem exists only in some third party keyboards (eg. SwiftKey) as the users requested this function.
    There is no other way to disable it except the trick with the input type. My workaround is to set the keyboard input type to a visible password field. This removes entirely the suggestions and removes the swipe function on some of keyboards too.
     
  3. Sandman

    Sandman Active Member Licensed User

    Yep, I just verified that that also works, and it disables the swipe. And for those wanting to try it out, the code is 0x91:

    upload_2018-1-13_20-9-24.png

    It's really a shame that we don't have a rock-solid method of disabling suggestions but have to fall back to these kinds of workarounds.
     
  4. panagiotisden2

    panagiotisden2 Member Licensed User

    There is a standard method for disabling suggestions but third party keyboard wont cooperate with this so third party keyboards is to blame.
     
  5. Sandman

    Sandman Active Member Licensed User

    Now we're getting off track, but I don't think that's a fair assessment. People and companies tend to try to get away with all they can get away with. (That's one of the reasons why most of us target older APIs, for instance. In this case it's Google's responsibility to limit what we get away with, hence the new limitations for APIs.) I think it's fair to say that Google should impose requirements to all third party keyboards to obey the keyboard flags. Thus I consider Google is to blame.
     
Loading...