【问题标题】:Sony SmartWatch2 : hooking back key索尼 SmartWatch2:挂钩返回键
【发布时间】:2013-10-24 01:10:40
【问题描述】:

在Sony SmartWatch2的控制扩展中,我可以通过onKey接收返回键,但是如何防止扩展终止?我想钩回键做一些过程,但按回键终止扩展。

在 SampleAdvancedControlExtension 中,它似乎通过启动新控件来阻止返回按钮,但我只使用单个控件。

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();
    }
}

好的,我找到了问题所在。我必须在 RegistrationInformation 类中添加以下方法。

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

【问题讨论】:

  • 我也遇到了同样的问题,别忘了把 manifest <action android:name="com.sonyericsson.extras.aef.control.KEY_EVENT" />

标签: android sony sony-smartwatch


【解决方案1】:

在“onBack()”方法中,对“stopRequest()”的调用是终止扩展的方法。 在你的情况下,你应该把你自己的逻辑放在这个方法中,这样如果你不需要它,“stopRequest()”就不会被调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多