Android: User Inaction / Discovery Login Detection (softkeyboard)

I want to detect "user inactivity" in my Android app. More precisely: I want to determine if the user has made any interaction with my application (touching the screen, scrolling, entering text ...) for a certain time. Technically, I use a timer that resets on every (user) interaction.

In my activity, I override the onUserInteraction method to detect interactions such as scrolling, touching the screen ...

@Override
public void onUserInteraction(){
    resetInactiveTimer();
}

Unfortunately, onUserInteraction is not called when the user interacts with the soft keyboard. I think the reason is that the soft keyboard is not part of my activity.

For edit texts in my application, I use TextWatcher and the onTextChanged method, which works fine. But my application also contains a WebView that loads arbitrary web pages. Of course, some web pages may contain input fields, and I don’t know how to detect that the user interacts with the soft keyboard to edit these text fields.

+5
source share
1 answer

Still interested in this?

Your business implements KeyEvent.Callback, so you can override onKeyDown:

@Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
    resetInactiveTimer();
    return false;
}

( ), EditText , OnKeyListener onKey resetInactiveTimer();

+1

All Articles