Question

I'm using the ControlExtension example from Sony SDK for SmartWatch 2. I have 4 buttons in the ControlExtension class. When one of these is clicked, the function onReceive() is called in a BroadcastReceiver, because the Intent filter com.sonyericsson.extras.aef.control.OBJECT_CLICK_EVENT
is registered in the manifest. But how can I know which of the buttons was clicked and if it was clicked or long pressed?

This is my 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);
    }
}



I also tried to register a click-handler in the ControlExtension and send an intent. The handler is called but the intent is not received (I also added the intent-filter in the manifest).

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

Solution 2

Found it out myself: There are some extras included in the intent:

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


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

OTHER TIPS

Looks like you were able to figure it out on your own but in addition you can look at the onObjectClick() and setupClickables() methods in the SampleControlSmartWatch2.java class for examples on how to handle button clicks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top