{"id":13645036,"url":"https://github.com/pqpo/InputMethodHolder","last_synced_at":"2025-04-21T11:32:33.957Z","repository":{"id":95094454,"uuid":"84076309","full_name":"pqpo/InputMethodHolder","owner":"pqpo","description":"A keyboard listener for Android which by hooking the InputMethodManager. 通过hook监听系统键盘显示","archived":false,"fork":false,"pushed_at":"2017-06-19T03:00:56.000Z","size":118,"stargazers_count":430,"open_issues_count":1,"forks_count":56,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-06T21:16:29.008Z","etag":null,"topics":["hook","inputmethod"],"latest_commit_sha":null,"homepage":"https://pqpo.me/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pqpo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-06T13:28:26.000Z","updated_at":"2025-01-07T03:27:37.000Z","dependencies_parsed_at":"2023-05-01T00:34:47.953Z","dependency_job_id":null,"html_url":"https://github.com/pqpo/InputMethodHolder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqpo%2FInputMethodHolder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqpo%2FInputMethodHolder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqpo%2FInputMethodHolder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqpo%2FInputMethodHolder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pqpo","download_url":"https://codeload.github.com/pqpo/InputMethodHolder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250048020,"owners_count":21366161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hook","inputmethod"],"created_at":"2024-08-02T01:02:24.056Z","updated_at":"2025-04-21T11:32:33.929Z","avatar_url":"https://github.com/pqpo.png","language":"Java","readme":"InputMethodHolder\n====\n\n\u003e A keyboard listener for Android which by hooking the InputMethodManager.\n  Of course you can also hook the other system services similarly,\n  If you want, create a class, make it a subclass of `Hook`, and using `ServiceManagerHook` to hook ServiceManager, learn more from `InputMethodManagerHook`.\n  If you like this project, ,welcome to fork or star!\n\nSteps：\n---------\n\n1.Import InputMethodHodler as a library  \n2.Call the initialization method, the method will hook InputMethodManager, recommended to call at `attachBaseContext`:\n```java\npublic class MyApplication extends Application {\n    @Override\n    protected void attachBaseContext(Context base) {\n        InputMethodHolder.init(base);\n        super.attachBaseContext(base);\n    }\n}\n```\n3.Register the listener,and unregister when unused：\n```java\nonInputMethodListener = new OnInputMethodListener() {\n    @Override\n\tpublic void onShow(boolean result) {\n\t    Toast.makeText(MainActivity.this, \"Show input method! \" + result, Toast.LENGTH_SHORT).show();\n\t}\n\t@Override\n\tpublic void onHide(boolean result) {\n\t    Toast.makeText(MainActivity.this, \"Hide input method! \" + result, Toast.LENGTH_SHORT).show();\n\t}\n};\nInputMethodHolder.registerListener(onInputMethodListener);\n```\n```java\n@Override\nprotected void onDestroy() {\n    super.onDestroy();\n    InputMethodHolder.unregisterListener(onInputMethodListener);\n}\n```\n4.Don't forget to release when exiting(avoid memory leaks)：\n```java\nInputMethodHolder.release();\n```\n\n**Please read Sample for getting specific use, and if have any problems please submit ISSUE.**\n\nDefect\n-----\n`onShow` works well in most situations, but `onHide` can only give callbacks by calling `hideSoftInputFromWindows` manually.\nThe reason is that system keyboard is hold by another process,\nand the procedure for using the keyboard by an application  is a local process remote call through `InputMethodManager`,\nthe hook is just that InputMethodManager of the application's process.\n\n```java\npublic interface OnInputMethodListener {\n    void onShow(boolean result);\n    void onHide(boolean result);\n}\n```\n\nSample\n----------\n\n![](http://ojlty2hua.qnssl.com/image-1488865989092-c2hvd2lucHV0LnBuZw==.png?imageView2/3/w/400/h/400/q/60|watermark/2/text/cWxtLnB3/font/5a6L5L2T/fontsize/500/fill/I0VGRUZFRg==/dissolve/100/gravity/SouthEast/dx/10/dy/10)  \n\n![](http://ojlty2hua.qnssl.com/image-1488866117210-aGlkZWlucHV0LnBuZw==.png?imageView2/3/w/400/h/400/q/60|watermark/2/text/cWxtLnB3/font/5a6L5L2T/fontsize/500/fill/I0VGRUZFRg==/dissolve/100/gravity/SouthEast/dx/10/dy/10)\n\nContact\n----\npqponet@gmail.com\n\nLicense\n--------\n    Copy right 2017. Linmin qiu\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.","funding_links":[],"categories":["软键盘"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpqpo%2FInputMethodHolder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpqpo%2FInputMethodHolder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpqpo%2FInputMethodHolder/lists"}