This is what logcat outputs, I've signed my android apk with my own cert
java.lang.NoSuchMethodException: com.example.receiver.InputManager.getInstance []
at java.lang.Class.getMethod(Class.java:2937)
at java.lang.Class.getDeclaredMethod(Class.java:2914)
at com.example.receiver.InputHandler.getInputManager(InputHandler.java:59)
at com.example.receiver.InputHandler.injectInputEvent(InputHandler.java:43)
at com.example.receiver.InputHandler.Handle(InputHandler.java:84)
at com.example.receiver.Main.main(Main.java:38)
at com.example.receiver.MainActivity.lambda$onCreate$0(MainActivity.java:21)
at com.example.receiver.MainActivity$$ExternalSyntheticLambda0.run(Unknown Source:2)
this is the code related to injectInputEvent()
private void injectInputEvent(MotionEvent event) {
try {
getInjectInputEvent().invoke(getInputManager(), event, 0);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
private static Method getInjectInputEvent() throws NoSuchMethodException {
Class<InputManager> cl = InputManager.class;
Method method = cl.getDeclaredMethod("injectInputEvent", InputEvent.class, int.class);
method.setAccessible(true);
return method;
}
private static InputManager getInputManager() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<InputManager> cl = InputManager.class;
Method method = cl.getDeclaredMethod("getInstance");
method.setAccessible(true);
return (InputManager) method.invoke(cl);
}
I have set the following permission in my manifest:
<uses-permission android:name="android.permission.INJECT_EVENTS"/>
I run my apk from adb shell like so:
am start com.example.receiver/com.example.receiver.MainActivity
This should work I think at it works for scrcpy's server why it doesn't for mine?
I don't have root access.
I was expecting for the app to be able to InjectInputEvents but it is not able to. I've tried starting it from adb shell and from android studio which didn't make any difference.