How to disable spell check programmatically in JB 4.3
I needed to disable spell checking so that product specific terminology wasn’t underlined in various dialogs / UI controls. As this is a customized AOSP build, the first thought was to disable it in the source. This proved problematic. After tracking down where the setting was set in the Settings app, simply changing the defaults there wasn’t enough. Digging further, I found in the system text service, the method I needed: setSpellCheckerEnabled(...)
. Of course it was hidden, but it was public. After trying the call in a couple different services, I realized that the process calling this method must be running as system.
try { Method setSpellCheckEnabledMethod; TextServicesManager tsm = (TextServicesManager) getApplicationContext().getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); Class<?>[] paramTypes = new Class[1]; paramTypes[0] = boolean.class; // Access the @hidden public method setSpellCheckerEnabled setSpellCheckEnabledMethod = tsm.getClass().getMethod("setSpellCheckerEnabled", paramTypes); Object[] params = new Object[1]; params[0] = false; setSpellCheckEnabledMethod.invoke(tsm, params); } catch (Exception e) { e.printStackTrace(); }