Convert keyboard height to UI sizes

Hi, I can’t figure out how to convert keyboard height to real size in game. I got keyboard height by native plugin and send it to Unity, smth like that:

rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        Rect r = new Rect();
                        rootView.getWindowVisibleDisplayFrame(r);
                        int screenHeight = rootView.getRootView().getHeight();
                        keyboardHeight = screenHeight - r.bottom;
                        boolean bKeyOpen = (keyboardHeight > screenHeight * 0.15);
                        float fKeyHeight = (float) keyboardHeight / (float) screenHeight;
                        JSONObject json = new JSONObject();
                        try {
                            json.put("msg", MSG_SHOW_KEYBOARD);
                            json.put("show", bKeyOpen);
                            json.put("keyheight", fKeyHeight);
                        } catch (JSONException e) {
                        }
                        SendUnityMessage(json);
                    }
                });

When plugin receive message, it converts to:

nKeyHeight = (int)( jsonMsg["keyheight"] * (float) Screen.height);

And after that, I want to set my gameobject above keyboard, but size is not correct. For example, I got keyboard height 746 on my Nexus 5. And when I set gameobject on it (vector2 (0, 746)) it appears not above keyboard.

So, pls, explain me how can I convert that value correctly?

You need to also check Screen height and width in Unity, they might be different from what you get in Java code and you then have to do proportional adjusting. Also, if your game object is in world coordinates, you need to check what coordinates your camera is showing.

I understand it, but not at all :frowning:
I’ve setup Canvas as on a screenshot, Camera projection is ortho.

3193340--243923--Screenshot at авг. 23 13-04-44.png

But, I don’ know how to convert 746 in correct height on screen

Try Screen.height and Screen.width from scripting and compare those with what you get in Java.

Sorry, my fault… I forgot to make screen ratio