5

Can Android Wearable apps detect the power button as a KeyEvent or by other means? I would like to run a listener service to detect the wearable power button.

I tried this but no log corresponding to a KeyEvent occurred.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.e(">>>>>>", "FindPhoneActivity event "+event);
    if (keyCode == KeyEvent.KEYCODE_POWER) {

        // Do something here...
        Log.e(">>>>>>", "FindPhoneActivity onKeyDown");
        //event.startTracking(); // Needed to track long presses
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

I have also experimented with two solutions used on normal android phone apps

  1. Registering a Broadcast Receiever
  2. Creating an onPause event with PowerManagement

Both methods described here. Android - how to receive broadcast intents ACTION_SCREEN_ON/OFF?

I tested the above with logs attached to the event but neither produced logs.

Community
  • 1
  • 1
Jack Shultz
  • 2,031
  • 2
  • 30
  • 53
  • Those should work fine. If not, you may want to consider running a Service on the phone and notifying the wearable. – m0skit0 Feb 17 '15 at 19:32

0 Answers0