Android Question How to close software keyboard globally?

artsoft

Active Member
Licensed User
Longtime User
Hi all!

Today I am faced with such an issue:

My app creates a notification if there is no action from user (like a screensaver).

This creates the notification:

B4X:
Dim n As Notification

Public Sub makeNotify(body As String)

    n.Initialize
  
    n.Sound        = False
    n.Insistent    = False
    n.Vibrate      = False
    n.Icon         = "icon"
    n.Light        = False
    n.OnGoingEvent = True
    n.AutoCancel   = True

    n.SetInfo("MyApp", body, Protect)
  
    n.Notify(19999)
  
End Sub

Public Sub cancelNotify()

    If (n.IsInitialized) Then
      
        n.Cancel(19999)
          
    End If
  
End Sub

The notification is created successfully.

As you can see:
By clicking this notification, the activity with the name "Protect" will be started and the activity is displayed successfully.


So far so good...

But, if I am working with another app which is using currently the software keyboard (in example: I am in Whatsapp and I am writing currently a message to a friend) and I click (in this scenario) my notification entry then my activity "Protect" is displayed on the smartphone screen - BUT WITH EMPTY SPACE (with the activiy BACKGROUND) at the same place where the software keyboard was in Whatsapp.

I cannot make a screenshot currently - because my app does not allow making screenshort (-> security).

Only the activity part above of the software keyboard is shown correctly.

I tried with IME to close the keyboard - but no effect!!

Therefore my question:
How I can close globally the software keyboard of my android smartphone in order to show my full activity (and not a part of it)?
Or is it possible to drive my app to redraw the full activity?


I need help here.

Thanks in advance.

Best regards
ARTsoft
 

artsoft

Active Member
Licensed User
Longtime User
Additional info for you:

I also forced my activity with name "Protect" to redraw all controls by using: Activity.Invalidate

So I can see that all controls from bottom (1 text and 1 button) are displayed now - but also with empty space:

1665388120590.png


The full activity with correct size is only displayed - after click on notification link - if this click happened when the software keyboard was not active!
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
You have to check the keyboard height, if the keyboard height is zero, then you resize your activity back to full screen

Thanks for your reply!

I am using the IME library with the HeightChangedEvent:

B4X:
Private Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int)
   
    Log("--------------------------- Old: " & OldHeight)
    Log("--------------------------- New: " & NewHeight)
   
End Sub

This event is triggered with these logged values:

--------------------------- Old: 1216
--------------------------- New: 2177


That means, that the first Y size (the current height of screen) while loading the layout of activity is only 1216.
--> Therefore I see the empty space below.

After raising this event, I can see the normal (full height) Y size of my screen, which is 2177.

Here I should have to resize my activity.... How can I "resize" my activity to full screen after this event?

In addition: How to check the size of the keyboard - if the keyboard was activated by another app?

Best regard
ARTsoft
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
Since the early days of Android I have continually had trouble with soft keyboards odd behaviour, especially when left open during device rotation.. The API is poorly designed and different devices from different manufacturers seem to have different quirks. I wrote an extended IME2 library which gives some extra information about the keyboard - it may help you or it may not!
 
Upvote 0
Top