android InputManager injectInputEvent [英] android InputManager injectInputEvent

查看:828
本文介绍了android InputManager injectInputEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读.我无法编译coredump给出的答案.我可以在InputManager.java(Android源代码)中清楚地看到injectInputEvent.它的公众也是如此.但是我无法编译它.可能是它的私有api,并且有一种访问它的方法.

I have read this. I am not able to compile the answer given by coredump. I can clearly see the injectInputEvent in InputManager.java (Android source code). Its public too. However I am not able to compile it. May be its a private api and there's a way to access it..

推荐答案

API被隐藏.您可以通过反射进行访问:

The API is hidden. You can access it by reflection:

InputManager im = (InputManager) getSystemService(Context. INPUT_SERVICE);

Class[] paramTypes = new Class[2];
paramTypes[0] = InputEvent.class;
paramTypes[1] = Integer.TYPE;

Object[] params = new Object[2];
params[0] = newEvent;
params[1] = 0;

try {
    Method hiddenMethod = im.getClass().getMethod("injectInputEvent", paramTypes);
    hiddenMethod.invoke(im, params);
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
    e.printStackTrace();
}

这篇关于android InputManager injectInputEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆