Where to put code for a global hardware key listener?

让人想犯罪 __ 提交于 2019-12-13 06:36:41

问题


I'm trying to hack hardware key support into an existing app, but came to realize I know too little of Android app development to continue.
I can decompile and recompile the app without problems using APKtool, and I made a small app myself with hardware key support to pull the compiled smali code out of. For reference, that part looks like this:

.method public onKeyDown(ILandroid/view/KeyEvent;)Z

If I want to have the app listen for hardware keys "globally" (i.e. in every activity, window, what-have-you, of the app), where ought I put the onKeyDown code? Do I put it in a single activity (if so, which one), in all activities, or someplace else altogether?

Edit: I realize "globally" is a bit ambiguous here. I mean throughout the entire app, not system-wide.


回答1:


If I want to have the app listen for hardware keys "globally" (i.e. in every activity, window, what-have-you, of the app), where ought I put the onKeyDown code?

You download the Android source code, modify it to have some sort of global hardware key handler, compile the modified source, package it into a ROM mod, and install the ROM mod on your device.

Otherwise, only the foreground activity (or, sometimes, window) will receive key events.



来源:https://stackoverflow.com/questions/18086097/where-to-put-code-for-a-global-hardware-key-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!