OnVirtualKeyboardShown event not firing

I have as situation where a form's OnVirtualKeyboardShown event is not firing when there is a map component on the form.
I have attached a simple demo that shows the behaviour. If I run the app without the map and tap on the edit box, the virtual keyboard appears and the OnVirtualKeyboardShown event fires (the label text changes to 'OnVirtualKeyboardShown fired'). If I then place a TTMSFNCMaps component onto the form and run the app again, the virtual keyboard appears (after tapping on the editbox) but the event doesn't fire (Label1 text doesn't change).
I have two android devices that I have run these tests on. One is a 64bit Samsung S8 phone (Android 9). The other is a 32bit Samsung SM-T710 tablet (Android 7). I have built the app as a 32 bit in release mode. The problem does not exist when run on the tablet; it only occurs on the phone.
I'm using Delphi 10.4.1 and have set the android:targetSdkVersion="28" in the AndroidManifest.template.xml file.
I'm thinking that there may be an incompatibility issue with the map component when running on an Android 9 device.

Project2.zip (8.7 KB)

The first image shows the correct behaviour when the edit box is tapped (no map). The second (with map) shows the form scrolling up a bit (I don't know why). When the keyboard is then closed, the label shows that the event didn't fire.

We'll investigate this here as soon as possible.


We have tested this here with Android SDK target version 28 on a Samsung Tablet with Android 9 and couldn't reproduce the issue. Can you check if you are using the default virtual keyboard? Did you test with the default targetSdkVersion ?

Hi Pieter. I am using the default virtual keyboard for the TEdit.
If I use the default target sdk version 26 in the manifest file then the event still doesn't fire. I also then get an incompatibility error after task swapping to another app and back to the test app. When set to 28, the incompatibility error does not occur.

The issue only occurs when the map is visible. If I set Map.Visible to false, the FormVirtualKeyboardShown event will fire.
Also, after the problem occurs, if I set the Map.Visible to false the map does not hide; it remains on screen.
I have also tested this on a new Samsung SM-T510 tablet running Android 9. It also doesn't fire the event. Some of the guys at work have also reported the problem on their phones.
The Chrome version on the T710 (works) and Phone (doesn't work) are the same so it's not an issue with the version of Chrome.
I suggest trying it on a few Android phones and tablets. If you can't reproduce the issue, can you make any suggestions on how I could track down the problem?

I guess that the focus is on the window that hosts the webview. So native events are triggered on the native window. It's strange that the focus isn't removed while focusing the edit, because I handle Enter & Exit events by taking away the focus. Can you perhaps do the following in the OnEnter event of the TEdit:

  AndroidApi.JNI.App, AndroidApi.JNI.GraphicsContentViewText,
  AndroidApi.JNI.WebKit, FMX.Helpers.Android;

procedure TForm1.RemoveFocus;
  w: JDialog;
  wb: JWebView;
  w := TJDialog.Wrap(TMSFNCWebBrowser1.NativeDialog);
  wb := TJWebView.Wrap(TMSFNCWebBrowser1.NativeBrowser);

    wn: JWindow;
    if Assigned(w) then
      wn := w.getWindow;
      if Assigned(wn) and Assigned(wb) then
        wn.addFlags(TJWindowManager_LayoutParams.JavaClass.FLAG_NOT_FOCUSABLE or TJWindowManager_LayoutParams.JavaClass.FLAG_ALT_FOCUSABLE_IM);

Hi Pieter.
I have put the RemoveFocus code in and called RemoveFocus within the OnEnter event of the TEditbox. I ran the app but it didn't fix the issue. I can confirm that the wb.clearFocus; line is executed.
I'm using a TTMSFNCMaps component; not explicitly a TTMSFNCWebBrowser so I had to change the first two lines of the RemoveFocus routine to;
w := TJDialog.Wrap(Map.NativeDialog);
wb := TJWebView.Wrap(Map.NativeBrowser);
I assume that is correct.
Is there something else I could try?
I haven't been able to come up with a work around. I need the FormVirtualKeyboardShown event to fire in order to get the Bounds of the virtual keyboard. I can't find an alternate way to get the bounds of the virtual keyboard.

So does the issue occur when targeting SDK 28, or only on SDK 26?

Either. When I change the target sdk in the manifest back to 26, is still doesn't work and O/S throws up a 'Detected problems with API compatibility' warning if I swap to a different app and come back again.

We'll investigate this further as soon as possible.

Thanks Pieter. Let me know if I can provide any further information to progress the investigation.

Hi, I have tested a new project and your existing project and couldn't reproduce the issue. I'm testing in 10.2 here in my current environment. I'm currently looking into a way to test in 10.4.1. Potentially, there is an underlying framework issue behind this.

Thanks Pieter. Is there any estimation on when you will be in a position to test this using 10.4.1?

I have just tested 10.4.1. There I'm able to reproduce the issue. In 10.2 I'm not able to reproduce the issue. After looking at the virtual keyboard implementation, it seems it has changed drastically and no longer functions correctly in combination with another native control. I think this will involve recompiling the fmx.dex.jar file to fix the issue which is a quite complex case. So this is considered an internal FMX framework issue / incompatibility. Can you provide additional info on why you need to OnVirtualKeyboardShown event? Perhaps you can switch to the OnEnter event instead?

Thanks Pieter, I'm so thankful that you have been able to reproduce the problem!
In my app I have an editbox that scrolls onto the screen when the user taps on control such as a TlistboxItem for example. The editbox should appear just above the virtual keyboard. To get the coordinates of the where the editbox should animate from and to I need the bounds (or height) of the virtual keyboard. The only way I know of to get the bounds of the keyboard when it appears is via the OnVirtualKeyboardShown event. If the event doesn't fire, I don't know where my editbox should animate from or to.
If you can think of another method of determining the height of the virtual keyboard then I could use that as a work around.

I'll further investigate this issue as soon as possible. Thanks for the additional info


We have changed the complete underlying browser approach and now, the event is triggered and the issue is fixed. The next version will address this. I've sent an incremental source update for testing purposes, check your private messages.

Thanks again Pieter. You have solved the problem. Well done!

1 Like