【问题标题】:Sony SmartWatch 2: Get button click in Host AppSony SmartWatch 2:在主机应用程序中单击获取按钮
【发布时间】:2014-03-19 07:21:40
【问题描述】:

我正在使用来自 Sony SDK for SmartWatch 2 的 ControlExtension 示例。我在 ControlExtension 类中有 4 个按钮。单击其中之一时,会在 BroadcastReceiver 中调用 onReceive() 函数,因为 Intent 过滤器com.sonyericsson.extras.aef.control.OBJECT_CLICK_EVENT
已在清单中注册。 但是我怎么知道哪个按钮被点击了,是被点击了还是长按了呢?

这是我的广播接收器:

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 中注册一个点击处理程序并发送一个意图。处理程序被调用但未收到意图(我还在清单中添加了意图过滤器)。

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

【问题讨论】:

    标签: android sony-smartwatch


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      @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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多