Native keyboard height and hide the input field

Hello everyone,

Its just a pain to get the native keyboard height in unity and then hide the native input field.
Hiding the input field work fine on ios and never on android.

For Getting the keyboard height I have searched and came out with several solutions which never worked.

For android none of the below worked for me.
printing them result in 0.

1-

TouchScreenKeyboard.area.height

2-

TouchScreenKeyboard.area.max.y

3 -

public int GetAndroidKeyboardSize()
    	{		
    		using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    		{
    			AndroidJavaObject View = UnityClass.GetStatic<AndroidJavaObject>("currentActivity").Get<AndroidJavaObject>("mUnityPlayer").Call<AndroidJavaObject>("getView");
    
    			using(AndroidJavaObject Rct = new AndroidJavaObject("android.graphics.Rect"))
    			{
    				View.Call("getWindowVisibleDisplayFrame", Rct);
    				return Screen.height - Rct.Call<int>("height");
    			}
    		}
    	}

4 -

private float GetKeyboardHeightRatio() 
    	{
    		#if UNITY_ANDROID        
    		using (AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
    			AndroidJavaObject View = UnityClass.GetStatic<AndroidJavaObject>("currentActivity").Get<AndroidJavaObject>("mUnityPlayer").Call<AndroidJavaObject>("getView");
    			using (AndroidJavaObject rect = new AndroidJavaObject("android.graphics.Rect")) {
    				View.Call("getWindowVisibleDisplayFrame", rect);
    				return (float)(Screen.height - rect.Call<int>("height")) / Screen.height;
    			}
    		}
    		#else
    		return (float)TouchScreenKeyboard.area.height / Screen.height;
    		#endif
    	}

Similarly no success on ios with methods 1&2 since 3&4 are only for android.

Temporarily I used a static size as the keyboard size (40% of canvas size) and the UI scaling works but just can’t get the value of the soft native keyboard.

And now want to hide the native input field, this time the trouble is only in android.

TouchScreenKeyboard.hideInput = true; ------ doesn’t work
this.GetComponent ().shouldHideMobileInput = true; ---- doesn’t work

Now before thinking of a plugin just to get a size or hiding the input field, let me know if someone has the simpler solution.

If we need a native plugin for this … too bad to unity.

Any help or useful links are appreciated.
btw I think I’ve checked all possible links, please suggest a method you’ve tried and worked for you.

I am using Unity 2017.3.1

thanks in advance

Hi @moghes,
I know this is an old question, but did you get any solution to this?
I am also stuck with the issue.

@moghes

TouchScreenKeyboard.area

Always return zero for Android - it`s written in the manual.

As far as I know code samples, which call native Android to get keyboard height will be work just when keyboard will be opened fully, you should await several seconds, before call this methods or use coroutines and with help yeild return new WaitUntil(predicate <bool>) wait until result will be non-zero, but I cant say, that its best solution.

About inputfield - cant remember any solutions at the Unity side, if I find any code snippets related to this question - Ill write here.