Android Onscreen Keyboard Won't reappear

#1

I’m having some Android keyboard problems. The first time I focus a texteditor control, the keyboard shows. I’m using the trick from this thread to hide it when a submit button is pushed:


But then the keyboard doesn’t re-appear when the same texteditor or another gets the focus.
I’m in fullscreen and kiosk mode, but that doesn’t stop the first appearance. Any trick to manually show and hide it? I can tolerate that in this app.

0 Likes

#2

Have you tried this on an actual device? This code is working fine for me on a Moto G6 Plus:

/*******************************************************************************
 The block below describes the properties of this PIP. A PIP is a short snippet
 of code that can be read by the Projucer and used to generate a JUCE project.

 BEGIN_JUCE_PIP_METADATA

  name:             AndroidTextEditorFocus

  dependencies:     juce_core, juce_data_structures, juce_events, juce_graphics, juce_gui_basics
  exporters:        androidstudio

  moduleFlags:      JUCE_STRICT_REFCOUNTEDPOINTER=1

  type:             Component
  mainClass:        MainComponent

 END_JUCE_PIP_METADATA

*******************************************************************************/

#pragma once


//==============================================================================
class MainComponent   : public Component
{
public:
    //==============================================================================
    MainComponent()
    {
        addAndMakeVisible (edit);
        addAndMakeVisible (hideButton);
        hideButton.onClick = [] { Component::unfocusAllComponents(); };
        
        Desktop::getInstance().setKioskModeComponent (getParentComponent(), false);
        
        setSize (600, 400);
    }
    
    ~MainComponent()
    {
    }
    
    //==============================================================================
    void paint (Graphics& g) override
    {
        g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
    }
    
    void resized() override
    {
        auto b = getLocalBounds().reduced (20);
        
        hideButton.setBounds (b.removeFromTop (35).reduced (20, 0));
        b.removeFromTop (20);
        edit.setBounds (b);
    }
    
    
private:
    //==============================================================================
    TextEditor edit;
    TextButton hideButton { "Hide" };
    
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};


0 Likes

#3

Thanks for the example - like the PIP thing!

So - on a Galaxy Tab S4, the keyboard appears the first time, hides as intended, but never comes back.

Same on the simulator set to version 27.

0 Likes

#4

Hi, did you type anything when you tested? If I just go focus/hide/focus, that works. But as soon as you enter anything in field, it’s gone.

0 Likes

#5

Here’s a clue: if there’s something in the text field it will not show up. A blank text editor given focus will show a keyboard, an editor with contents will not.

This is obviously a show stopper on Android.

I can maybe blank the fields and let the user enter stuff, but they would be unable to go back and edit a typo if they move focus.

0 Likes

#6

Ah, that was it. I’ve pushed a fix to develop here that should fix the issue.

1 Like

#7

Great, thank you - works perfectly!

0 Likes

#8

OK, damn.
https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#setInputMethod(android.os.IBinder,%20java.lang.String)

setInputMethod is marked as deprecated in API 28. Maybe someone got keen and pulled it early? Or is it that the strings don’t match/changed - I can’t find that list. Trying to get to it in debugger now.

This guy claims it’s a security thing?

0 Likes