App doesn't catch onkeydown after opening in Android 10
Application Type
Mobile
Service Studio Version
11.10.12 (Build 39238)
Platform Version
11.7.3 (Build 7036)

Hi all,


I've added an event listener in a mobile Android app to listen for specific keys (F1, F2 and F3) being clicked. This because we're using an enterprise device (Zebra Wearable) which has 3 physical keys that are mapped to these F-keys. This always worked for our apps that ran on devices with Android 7.1.1. 

We did this with the following code in a JS node in the OnReady:

document.onkeydown = function(e) {

    e = e || window.event;

    try{

        $actions.PhysicalButtonOnClick(event.keyCode);

    }catch(err){

        console.log('could not find the PhysicalButtonClick action. Error: '+err.message)

    }

};


Recently we switched to new devices with Android version 10, and only on these new devices we have a problem with this keylistener not picking up the buttonclicks after opening the app. The old devices still works fine. 

I found a few workarounds to make it work:

  • After i clicked the screen once, i can press the F-keys and they are being catched;
  • After i click the appswitcher button (square native Android button) and select the app again, the F-keys are working;
  • After going back to the Android home screen, and opening the app again (from the background, the F-keys are working.

I've tried the following things without success:

  • Bind the event listener to the 'window' object;
  • Using 'FocusIt' or 'ClickIt' actions in the OnReady to set the focus to different input/container elements;
  • We're still using MABS 6.3.3 to build our apps, upgrade to MABS 7 doesn't fix this problem;
  • Android > Settings > Apps > 'OurAppName' > advanced > display over other apps > true;
  • Create a new simple testapp to make sure other functionality in our apps is not causing this issue (i attached the .oml).

This leaves me thinking that the app is not in focus after a clean start in Android 10 (API Level 29). I know it's opened in a Cordova shell (android.webkit.WebView) but this is also the point my knowledge stops a bit. Can anyone help finding the cause of this problem and fix it?


If you need more information please let me know.


Kind Regards,

Jobbe Maas

AndroidFocusTestApp.oml

Here a video to make the difference more clear. Left is the old device which works fine. Right is the new device which is not working.

oldvsnew.zip

I gathered Logcat logs of both devices from the moment op opening the app untill a few seconds after clicking the button. After analysis there's one remarkable difference between both:

In Android 7.1.1, after opening the app, one of the lines in the logcat logging is:

"LatinIME: onStartInput(<AppIdentifier>: 0x100 (null))"

The logs of Android 10 doesn't show this line after opening the app, but only after clicking the app after it is already opened. It seems like this has something to do with the issue i'm facing.

Is there anyone that can help with this?

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.