问题
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