-2

I wants to check that if user open the keypad then i wants to show a alertbox. How can i do this? if background service is required than can anyone tell me how to detect user opens the keypad.

I want to detect with normal use of phone.like if user open keypad to call then one alert box shows.

Please help me.

Code Program
  • 35
  • 1
  • 2
  • 7
  • possible duplicate of [Close/hide the Android Soft Keyboard](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – flx Sep 13 '13 at 06:26
  • @flx I want to detect with normal use of phone.like if user open keypad to call then one alert box shows. – Code Program Sep 13 '13 at 06:31

1 Answers1

0

Try this way

try {
        activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {

                Rect r = new Rect();
                getScreenRootView().getWindowVisibleDisplayFrame(r);


                int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
                if (heightDiff > 100) {
                    // keypad is open
                } 
            }
        });
    } catch (Throwable e) {
        e.printStackTrace();
    }
Biraj Zalavadia
  • 27,124
  • 9
  • 56
  • 73