How to trigger onText event in LatinIME - android

Base on Hacker's Keyboard, I want to send text from GCM (Google Cloud Messaging) to current input (textbox).
So, how can I trigger onText event on LatinIME.java to send text (through CharSequence text to current input)
public void onText(CharSequence text) {...}

That's not how you would do it. LatinIME is a specific keyboard- Google's. It may or may not be installed (Samsung doesn't use it). And the input connection is something that exists only to talk to the IME because its a separate process. Its also pretty much a 1 way interface- you don't cause text events in the keyboard.
You're also overthinking things. This is your app. Just use setText() on the view. If you want this to happen even outside your app, you couldn't do that anyway (the keyboard only communicates with a single app at a time).

Related

Android . Activating my application when some string was entered in some other application

I am trying to create a behavior where entering some string in any application will open my application.
I've tried looking around on how to listen for keyboard press or listening for text change, but I couldn't find my required behavior and I don't want to create a custom keyboard for this.
If this is not possible, what will be a good implementation for lunching my application as fast as possible while in the other application?
Answered before the requirement to "don't want custom keyboard"
The only viable way that I can think of is if the user was using a custom keyboard written by you. Custom keyboards can and do act as key-loggers and therefor could detect any key combination, or written word and allow you to execute your code when your conditions are met.
Rerfer to Creating an input method docs
How to open my app as fast as possible from another application?
Press home, launch your app by clicking on the launcher icon
But assuming you mean without doing that, you'll still need to monitor some event, say volume keys pressed or device being shaken for instance, or have you app be running already in the foreground such as what Facebook messenger does (or used to do, I don't know)
Related questions:
What APIs in Android is Facebook using to create Chat Heads?
Listen to volume buttons in background service?
How to detect shake event with android?
Demo of bubbles

Google keyboard doesn't call commitText() on pressing Enter

I have written a custom InputConnection by extending android's BaseInputConnection. I used to get commitText() when the user presses Enter Key. But recently with Google Keyboard, this doesn't happen. Google Keyboard sends sendKeyEvent() with the parameter being enterKeyUp and enterKeyDown events. However, I don't get the predicted text, as I used to get in commitText(). How can I get the predicted text on pressing EnterKey in Googke Keyboard?
Did they actually have a composing region? If not they may have decided no commit text was necessary. Or did you tell them your input type was NULL? If so, they may have gone into dumb mode and sent everything as key events.
They also may have called FinishComposingText instead, which tells the editor that the existing text is good (no correction). But its generally not a good idea to assume a certain action will come from a certain event because keyboards are always working around bugs in bad input connection implementations to get the effect they want. Just implement InputConnection as best you can and do what it says, rather than expect certain events at certain times.

Android: Global Key Listener

I am writing an android app which will record the frequency and timestamps of when a user is using their keyboards (soft or hard) (Example: a parent checking to see if their child was texting during school by giving them timestamps and frequency of key presses). This wouldn't need to know what was being typed, just when something was typed. It would also need to function regardless of what app was using the keyboard.
This is not possible, except perhaps via custom firmware.

Key event handling process

I'd like to know how the key event is handled in Android platform.
From 'when user type key 'a' on software keyboard',
To 'view draw the character 'a' on itself'.
Probably, the key event is generated by IME,
And it will be sent to parent view,
Finally, view(such as EditText) displays chracters.
Please somebody explains about these entire key event handling process.
Take a look at this article: http://developer.android.com/resources/articles/creating-input-method.html
Basically, you can either manually send KeyEvents or you can manually edit and commit text around the cursor in the application's Input View.
These are all done via your IME's InputConnection.
OnKeyListener and OnKeyDown do not get called, as you have discovered, when using a software keyboard. They only get called when using a hardware keyboard, which many Android devices don't even have.
I assume what you are trying to do is capture key events as they are occurring in an EditText area. Your best bet in this case, in order to handle both software keyboard input and hardware keyboard input, is to register a TextWatcher via the addTextChangedListener() method.
Note that on phones with Android 2.1 and later, such as the Nexus One, people have the option of using speech recognition to input text into your EditText instead of typing the text. When they do that you may get full words, or even full sentences, entered all at once. So you need to check the entire contents of the EditText field when there is a change to the contents.

Text Entry on an Android Custom View

I'm dealing with a phone that has no physical keyboard and I'm using my own custom view for rendering. The device I'm working with, by default, seems to be in a T9 type entry mode where it suggests blocks of text. However, it never sends me the actual key events.
How do I tell whatever soft-keyboard that pops up to enter 'dumb' key event sending mode?
The InputMethodManager has a "isAcceptinText()" call which would tell me if it's in event-sending mode, but not a method to set it. Digging through the documentation hasn't produced any insight. How do I tell the input manager that I only want key events?
I think this page has pretty much all there is to say on Android Input method control: Android - Onscreen Input Methods

Categories

Resources