1

My android app has a function to detect all the keycodes for TV remote.

I tried onKeyDown(up) API to detect when the user press the TV remote and override dispatchKeyEvent method too. It works except some keys : mute, volume, home, back. how can I detect those keys?

Thanks,

Guopeng Li
  • 81
  • 1
  • 9

2 Answers2

0

The system has the privilege to control those keys, so I have to find some source code to use.

I final resolved this problem. In general, AOSP dispose a led service (led controller):

  public LedService() {
    }

    public IBinder onBind(Intent intent) {
        this.handlePowerStateChanged(0);
        return new LedService.LedServiceWrapper();
    }

    public void handlePowerStateChanged(int state) {
        if (DEBUG) {
            Log.d(TAG, "handlePowerStateChanged: " + state);
        }

    }

    public void handleKeyEvent(KeyEvent event) {
        if (DEBUG) {
            Log.d(TAG, "handleKeyEvent: " + event);
        }

    }

This class use HAL to go down the level and communicate directly with system. I extend this class in my own class and use handleKeyEvent method.

Cheers,

Guopeng Li
  • 81
  • 1
  • 9