Sony SmartWatch2 : hooking back key

僤鯓⒐⒋嵵緔 提交于 2020-01-13 05:12:09

问题


In control extension for Sony SmartWatch2, I can receive back key through onKey, but how can I prevent extension from terminating? I want to hook back key to do some process, but pressing back key terminates extension.

In SampleAdvancedControlExtension, it seems like it is blocking back button by starting new control, but I'm only using single control.

public void onKey(int action, int keyCode, long timeStamp) {
    Log.v(SampleExtensionService.LOG_TAG, "onKey");

    if (action == Control.Intents.KEY_ACTION_RELEASE
            && keyCode == Control.KeyCodes.KEYCODE_BACK) {
        Log.d(SampleExtensionService.LOG_TAG, "onKey() - back button intercepted.");
        onBack();
    } else if (mCurrentControl != null) {
        super.onKey(action, keyCode, timeStamp);
    }
}

/**
 * Closes the currently open control extension. If there is a control on the
 * back stack it is opened, otherwise extension is closed.
 */
public void onBack() {
    Log.v(SampleExtensionService.LOG_TAG, "onBack");
    if (!mControlStack.isEmpty()) {
        Intent backControl = mControlStack.pop();
        ControlExtension newControl = createControl(backControl);
        startControl(newControl);
    } else {
        stopRequest();
    }
}

Ok, I figured out the problem. I had to add following method in RegistrationInformation class.

@Override
public boolean controlInterceptsBackButton() {
    // Extension has it's own navigation, handles back presses.
    return true;
}

回答1:


In "onBack()" method the call to "stopRequest()" is the one that terminates the extension. In your case you should just put your own logic in this method, so that "stopRequest()" won't be called if you don't need it.



来源:https://stackoverflow.com/questions/19555150/sony-smartwatch2-hooking-back-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!