TouchScreenKeyboard.visible is always false on Android

I am using a WebView plugin to display some web page, and the user can input some text on it. I want to know if the on-screen keyboard is visible or not. I use this static variable,

TouchScreen.Keyboard.visible

On iOS5, it works perfectly, but on Android (tested on Galaxy S2) it always returns false. The Rect area is also always zero :frowning:

I am using Unity 4.1.2. Is there any workaround for this? Do I need to write a native plugin myself?

In the end, I wrote a native implementation inside the WebView plugin, because it seems Unity can’t know when the keyboard has been opened from the WebView.

		final View activityRootView = a.getWindow().getDecorView().getRootView();
		activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {
		@Override
		public void onGlobalLayout() {
				android.graphics.Rect r = new android.graphics.Rect();
				//r will be populated with the coordinates of your view that area still visible.
				activityRootView.getWindowVisibleDisplayFrame(r);
				android.view.Display display = a.getWindowManager().getDefaultDisplay();
				int screenHeight = display.getHeight();
				int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
				//System.out.print(String.format("[NativeWebview] %d, %d

", screenHeight, heightDiff));
if (heightDiff > screenHeight/3) { // assume that this means that the keyboard is on
UnityPlayer.UnitySendMessage(gameObject, “SetKeyboardVisible”, “true”);
} else {
UnityPlayer.UnitySendMessage(gameObject, “SetKeyboardVisible”, “false”);
}
}
});