【发布时间】: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