Android - Runtime enable/disable debug options

  I have been used to control application debug options via adb shell or recompilation with debug turned on etc. Although this works fine, in some cases its not convenient, especially when testers work on the applications.

   So found this nice little trick that lets anyone enable and disable debug options. It doesn't need the app to be recompiled or access to adb. Users would just need to increase or decrease the volume to control the debug options.


   DebugActivity extends Activity {

          public boolean dispatchKeyEvent (KeyEvent event) {

                 final int keyCode = event.getKeyCode();
                 if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                      // Enable Debug options
                 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                      // Disable Debug options
                 }

          }

   }

No comments: