V. Kovar
V. Kovar

Reputation: 11

Focus html input after returning from android intent in IME

I have a pretty basic IME soft keyboard written in java. I also have a website with basic HTML text inputs.

My keyboard has one special button that launches activity. There I can read data from NFC chip and send them back. That works fine, I return to my website. But since the keyboard is closed now, my text string is not pasted into input until I click on it.

Is there any way to force the input field to act like google searchview? Like this:

  1. User focused field
  2. User clicked on the button, was redirected with intent to new activity
  3. User got data, dismissed activity
  4. Field was refocused, data inserted.

I use this piece of code to commit my text

       public void onStartInputView(final EditorInfo editorInfo, final boolean restarting) {
           if (hasMessages(MSG_PENDING_IMS_CALLBACK)
                   && KeyboardId.equivalentEditorInfoForKeyboard(editorInfo, mAppliedEditorInfo)) {
               // Typically this is the second onStartInputView after orientation changed.
               resetPendingImsCallback();
           } else {
               if (mPendingSuccessiveImsCallback) {
                   // This is the first onStartInputView after orientation changed.
                   mPendingSuccessiveImsCallback = false;
                   resetPendingImsCallback();
                   sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK),
                           PENDING_IMS_CALLBACK_DURATION_MILLIS);
               }
               final LatinIME latinIme = getOwnerInstance();
               if (latinIme != null) {
                   executePendingImsCallback(latinIme, editorInfo, restarting);
                   latinIme.onStartInputViewInternal(editorInfo, restarting);
                   mAppliedEditorInfo = editorInfo;

                   CharSequence text = DataHolder.getData();
                   if (text != null)
                   {
                       latinIme.getCurrentInputConnection().commitText(text, 1);
                       DataHolder.setData("");
                   }


               }
               cancelDeallocateMemory();
           }
       }

Seems like that works fine - since the keyboard is closed after activity return I can't commit text.

I'm getting kinda desperate as I'm stuck on this for a few days already. Thanks!

Upvotes: 1

Views: 106

Answers (0)

Related Questions