I need to be able to conditionally enable the incognito/private mode on android keyboards inside a webview.
For regular inputs there is the setImeOptions()
method which works fine but the WebView class doesn't appear to have that and the only possible hook I could find is overriding onCreateInputConnection
like I've attempted below:
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
if(privateBrowsingEnabled){
Log.d("INCOG", "Enabling private keyboard mode "+outAttrs.imeOptions );
outAttrs.imeOptions |= IME_FLAG_NO_PERSONALIZED_LEARNING;
}else{
Log.d("INCOG", "Disabling private keyboard mode "+outAttrs.imeOptions );
outAttrs.imeOptions = IME_NULL;
}
return super.onCreateInputConnection(outAttrs);
}
The overridden method is called but changing the imeOptions property doesn't appear to have any effect on the keyboard.
Was looking to do this myself and the following snippet ended up working for me:
My guess is super.onCreateInputConnection() overrides imeOptions so you have to set the flag after calling super.
I'm using the latest version of GBoard which supports incognito mode.