How to open/close soft keyboard on a native Android application and extract full text without using key events?

482 views
Skip to first unread message

Andy Slater

unread,
Jul 9, 2012, 3:45:51 AM7/9/12
to andro...@googlegroups.com

Hello,

I'm writing a Android NDK application, targeted at API 8, based on the hello-gl2 example and so uses a single full-screen OpenGL2.0 view, (extended GLSurfaceView).

I need to bring up the on-screen keyboard and pass the user entered text down to c code processing. I've managed to get this working based on this stackoverflow answer, (I don't get notification if the user closes the keyboard but from comments elsewhere in this group that seems to be the way things are. :)

All is well with this method until i switch to Swype or any other more-advanced-then-stock keyboard input manager then i rarely get the key events.
After reading the KeyEvent developer doc class overview what i'm seeing seems to be the expected behaviour:

 "You should never rely on receiving KeyEvents for any key on a soft input method."

So i've been trying to work out a way in which to capture and/or extract text and i'm not having much luck.

I've got this code in my extended GLSurfaceView class:

  @Override
  public InputConnection onCreateInputConnection(EditorInfo outAttrs)
  {
      outAttrs.actionLabel = "";
      outAttrs.hintText = "";
      outAttrs.initialCapsMode = 0;
      outAttrs.initialSelEnd = outAttrs.initialSelStart = -1;
      outAttrs.label = "";
      outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
      outAttrs.inputType = InputType.TYPE_NULL;

      return new BaseInputConnection(this, false);
  }

  @Override
  public boolean onCheckIsTextEditor()
  {
    return true;
  }

And i'm calling:

  public boolean showSoftInput(View view, int flags)

passing in the view returned from 'getCurrentFocus', from native code to display the keyboard.

Is it possible to be able to extract the text from the on-screen software keyboard not using the keyup event?
Is it possible to update what i've got to be able to do this or should i be looking at a completely different method?

Apologies for the questions, as you can tell, the non-native Java side of Android development is quite new to me. :)

Many thanks for any help or advice offered,
Andy

Andy Slater

unread,
Jul 11, 2012, 4:29:07 AM7/11/12
to andro...@googlegroups.com
Anyone? Even a clue? ;)
Thanks,
Andy
Reply all
Reply to author
Forward
0 new messages