title: How to detect keyup and keydown event in service
body: <p>I have a CustomView which extends <code>LinearLayout</code> , I am adding it to screen using <code>WindowManager.addView()</code> method to detect key event in my service with following layout param flags</p>
  
  <pre><code>  LinearLayout mLinear = new LinearLayout(getApplicationContext()) {
          @Override
          public boolean dispatchKeyEvent(KeyEvent event) {
              super.dispatchKeyEvent(event);
              Log.i(TAG, "event");
  
              int action = event.getAction();
              int keyCode = event.getKeyCode();
              switch (keyCode) {
  
                  case KeyEvent.KEYCODE_VOLUME_UP:
                      Log.i("Key", "VolumeUp");
  
                      return true;
                  case KeyEvent.KEYCODE_VOLUME_DOWN:
                     Log.i("Key", "VolumeDown");
                      return true;
  
                  case KeyEvent.KEYCODE_BACK:
                      Log.d(TAG, " " + "KEYCODE_BACK");
  
                      return false;
  
                  default:
                      return true;
              }
  
          }
  
      };
  
      mView = LayoutInflater.from(this).inflate(R.layout.volume_service_layout, mLinear);
      wm = (WindowManager) getSystemService(WINDOW_SERVICE);
  
  
      if (mView.getVisibility() == View.VISIBLE)
          flag =  WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING ;
  
  
      //params
      params = new WindowManager.LayoutParams(
              100,
              100,
              WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
              WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
              PixelFormat.TRANSLUCENT);
      params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
      wm.addView(mView, params);
  
  }
  </code></pre>
  
  <p><code>dispatchKeyEvent()</code> is override in <code>customview</code> class,but after adding it to windows back press <code>Button</code> not working.When I am adding <code>WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE</code> flag backpress button working fine,I am unable to detect keyup and keydown event.</p>
  
  <p>I want to detect keyup or keydown event in service class.
  Please suggest any solution for this problem.</p>