https://github.com/pqpo/inputmethodholder
A keyboard listener for Android which by hooking the InputMethodManager. 通过hook监听系统键盘显示
https://github.com/pqpo/inputmethodholder
hook inputmethod
Last synced: about 2 months ago
JSON representation
A keyboard listener for Android which by hooking the InputMethodManager. 通过hook监听系统键盘显示
- Host: GitHub
- URL: https://github.com/pqpo/inputmethodholder
- Owner: pqpo
- License: apache-2.0
- Created: 2017-03-06T13:28:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-19T03:00:56.000Z (almost 8 years ago)
- Last Synced: 2025-03-30T19:11:06.656Z (about 2 months ago)
- Topics: hook, inputmethod
- Language: Java
- Homepage: https://pqpo.me/
- Size: 115 KB
- Stars: 430
- Watchers: 11
- Forks: 56
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
InputMethodHolder
====> A keyboard listener for Android which by hooking the InputMethodManager.
Of course you can also hook the other system services similarly,
If you want, create a class, make it a subclass of `Hook`, and using `ServiceManagerHook` to hook ServiceManager, learn more from `InputMethodManagerHook`.
If you like this project, ,welcome to fork or star!Steps:
---------1.Import InputMethodHodler as a library
2.Call the initialization method, the method will hook InputMethodManager, recommended to call at `attachBaseContext`:
```java
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
InputMethodHolder.init(base);
super.attachBaseContext(base);
}
}
```
3.Register the listener,and unregister when unused:
```java
onInputMethodListener = new OnInputMethodListener() {
@Override
public void onShow(boolean result) {
Toast.makeText(MainActivity.this, "Show input method! " + result, Toast.LENGTH_SHORT).show();
}
@Override
public void onHide(boolean result) {
Toast.makeText(MainActivity.this, "Hide input method! " + result, Toast.LENGTH_SHORT).show();
}
};
InputMethodHolder.registerListener(onInputMethodListener);
```
```java
@Override
protected void onDestroy() {
super.onDestroy();
InputMethodHolder.unregisterListener(onInputMethodListener);
}
```
4.Don't forget to release when exiting(avoid memory leaks):
```java
InputMethodHolder.release();
```**Please read Sample for getting specific use, and if have any problems please submit ISSUE.**
Defect
-----
`onShow` works well in most situations, but `onHide` can only give callbacks by calling `hideSoftInputFromWindows` manually.
The reason is that system keyboard is hold by another process,
and the procedure for using the keyboard by an application is a local process remote call through `InputMethodManager`,
the hook is just that InputMethodManager of the application's process.```java
public interface OnInputMethodListener {
void onShow(boolean result);
void onHide(boolean result);
}
```Sample
----------

Contact
----
[email protected]License
--------
Copy right 2017. Linmin qiu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.