Sony SmartWatch 2:在Host App中单击“获取”按钮

时间:2014-03-18 18:36:43

标签: android sony-smartwatch

我正在使用Sony SDK for SmartWatch 2的ControlExtension示例。我在ControlExtension类中有4个按钮。单击其中一个时,在BroadcastReceiver中调用onReceive()函数,因为Intent过滤器com.sonyericsson.extras.aef.control.OBJECT_CLICK_EVENT
在清单上登记。 但是,如何知道点击了哪些按钮以及是否单击或长按了这些按钮?

这是我的BroadcastReceiver:

public class ExtensionReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, final Intent intent) {

        Log.d(SampleExtensionService.LOG_TAG, "onReceive: " + intent.getAction());
        intent.setClass(context, SampleExtensionService.class);
        context.startService(intent);
    }
}



我还尝试在ControlExtension中注册一个click-handler并发送一个intent。调用处理程序但未收到intent(我还在清单中添加了intent-filter)。

Intent i = new Intent("com.sonyericsson.extras.aef.control.TEST");
sendToHostApp(i);

2 个答案:

答案 0 :(得分:1)

看起来您可以自己解决这个问题,但另外您可以查看SampleControlSmartWatch2.java类中的onObjectClick()和setupClickables()方法,以获取有关如何处理按钮点击的示例。

答案 1 :(得分:0)

自己发现: 意图中包含一些额外内容:

@Override
public void onReceive(final Context context, final Intent intent) {
    int layoutId = intent.getIntExtra(Control.Intents.EXTRA_LAYOUT_REFERENCE, -1);
    int clickType = intent.getIntExtra(Control.Intents.EXTRA_CLICK_TYPE, -1);
}


文档:
http://developer.sonymobile.com/reference/sony-addon-sdk/com/sonyericsson/extras/liveware/aef/control/Control.Intents#CONTROL_OBJECT_CLICK_EVENT_INTENT

相关问题