• Stars
    star
    424
  • Rank 102,329 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A keyboard listener for Android which by hooking the InputMethodManager. 通过hook监听系统键盘显示

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:

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:

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);
@Override
protected void onDestroy() {
    super.onDestroy();
    InputMethodHolder.unregisterListener(onInputMethodListener);
}

4.Don't forget to release when exiting(avoid memory leaks):

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.

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 at

   http://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.

More Repositories

1

SmartCropper

🔥 A library for cropping image in a smart way that can identify the border and correct the cropped image. 智能图片裁剪框架。自动识别边框,手动调节选区,使用透视变换裁剪并矫正选区;适用于身份证,名片,文档等照片的裁剪。
Java
3,924
star
2

SmartCamera

📷SmartCamera 是一个 Android 相机拓展库,能够实时采集并且识别相机内物体边框是否吻合指定区域。SmartCamera is an Android camera extension library,provides a scanning module that can recognizes whether the object's border inside the camera matches the area in real time.
Java
1,254
star
3

Log4a

:octocat:Log4a is an mmap based, high-performance, highly available Android log collection library / Log4a 是一个基于 mmap, 高性能、高可用的 Android 日志收集框架
Java
963
star
4

MethodHook

hook java methods
Java
134
star
5

PLock

🔐PLock is a simple and efficient cross-process lock, also support read-write lock. (简单高效的跨进程锁,支持读写锁分离)
Java
105
star
6

AIPoet

基于人工智能(障)的 Android 写诗应用,无须联网随时随地写藏头诗,意境诗。娱乐、学习为主!
Kotlin
91
star
7

CppPrimer

c++学习代码
C++
18
star
8

ServiceAndIpcDemo

Service lifecycle and IPC Demo
Java
11
star
9

MvpGenerator

IntelliJ Idea 插件,生成Mvp模板代码
Java
7
star
10

load_another_app_resource

Load another application's resource like RemoteView do, just for fun!(像 RemoteView 一样加载其他应用的资源)
Java
6
star
11

start_undeclared_activity

Start an activity that is not declared in the AndroidManifest.xml (It's a demo, just for fun) 启动一个未注册的 Activity
Java
4
star
12

appiumn_auto_re-develope

Louis-me/appiumn_auto 该项目二次开发,以适应测试人员使用(无需编写任何python代码)
Python
3
star
13

registration_api

远程挂号系统api
Java
2
star
14

SimpleEncrypt

简单文件加密
Java
1
star
15

pqpo.github.io

HTML
1
star
16

android.asyncImageLoader

异步图像加载工具,可设置本地缓存,内存缓存,内存缓存使用弱引用防止内存溢出
Java
1
star