So as I mentioned in a previous post I recently got a Sony Ericson LiveView watch, I decided to download the SDK and have a go at writing a plugin for use with the watch. The SDK is easy to use (developer world) and the examples and documentation (available here) is very clear and easy to understand. Unfortunately there is no emulator so you will have to go to the trouble of owning one of these devices if you want to test your app on it.
There are two types of plugins.
1. Announce plug-in
Announce plug-ins can send announcements to the LiveViewâ„¢ device. This is done in
the same way as the predefined announce features, like Facebook and Twitter.

Gmail Plugin Emails
The SDK Announce plugin (helloWorldPlugin) example is very simple and and mostly contains code scheduling a timer to send events to the phone along. This is a single class which is supported by a small number of helper classes and the plugin only contains a few things foreign to a typical android application:
Just extend the class provided by the SDK for plugins:
public class HelloWorldService extends AbstractPluginService {
Send updates to the phone using the following function:
mLiveViewAdapter.sendAnnounce(mPluginId, mMenuIcon, header, body, System.currentTimeMillis(), "https://en.wikipedia.org/wiki/Hello_world_program");
Where:
mPluginId – identifies which app send the update
mMenuIcon – the icon the update will appear with
header – the title (IE: email subject)
body – the main text (IE: email text)
timestamp – timestamp of the announcement
link – action to perform when user clicks at end of message (event to occur on phone). This is interpreted by overriding the function below:
@Override
protected void openInPhone(String openInPhoneAction) {
Log.d(PluginConstants.LOG_TAG, "openInPhone: " + openInPhoneAction);
// Open in browser.
final Uri uri = Uri.parse(openInPhoneAction);
final Intent browserIntent = new Intent();
browserIntent.setData(uri);
browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(browserIntent);
}
2. Sandbox
The sandbox plug-in can take complete control of the LiveViewâ„¢ device by sending
images to it and control its ability to vibrate and display different colors on the LED. All
user activities are propagated to the plug-in, so that it can take appropriate actions.

Contact Call Plugin
We extend the same class however this time we say yes when we are asked if we are a sandbox plugin:
@Override
protected boolean isSandboxPlugin() {
return true;
}
So now rather than using sendAnnounce to send text to the liveview we directly send images. Below is a function used that draws some text to a bitmap and then sends it to be displayed.
public static void sendTextBitmap(LiveViewAdapter liveView, int pluginId, String text, int bitmapSizeX, int fontSize) {
// Empty bitmap and link the canvas to it
Bitmap bitmap = null;
try {
bitmap = Bitmap.createBitmap(bitmapSizeX, fontSize, Bitmap.Config.RGB_565);
}
catch(IllegalArgumentException e) {
return;
}
Canvas canvas = new Canvas(bitmap);
// Set the text properties in the canvas
TextPaint textPaint = new TextPaint();
textPaint.setTextSize(fontSize);
textPaint.setColor(Color.WHITE);
// Create the text layout and draw it to the canvas
Layout textLayout = new StaticLayout(text, textPaint, bitmapSizeX, Layout.Alignment.ALIGN_CENTER, 1, 1, false);
textLayout.draw(canvas);
try
{
liveView.sendImageAsBitmap(pluginId, centerX(bitmap), centerY(bitmap), bitmap);
} catch(Exception e) {
Log.d(PluginConstants.LOG_TAG, "Failed to send bitmap", e);
}
}
So we can create a similar function drawing whatever we want to a bitmap and then passing it onto the screen.
Only one thing left (I think). Intercepting button presses:
@Override
protected void button(String buttonType, boolean doublepress, boolean longpress) {
....
}
Where the the following buttons are defined:
- PluginConstants.BUTTON_UP
- PluginConstants.BUTTON_DOWN
- PluginConstants.BUTTON_LEFT
- PluginConstants.BUTTON_RIGHT
- PluginConstants.BUTTON_SELECT
and we can see if the were tapped or held down with the boolean longpress. Note that we cannot detect longpresses of select as that will exit your plugin and the power button at all as that controls the screen.
My Attempt at a plugin: Alarm Clock
So I thought given that this thing is pretty much a watch, it would be useful to be able to set an alarm with it.

Plugin Icon

12hr clock (select sets alarm)

24hr clock
Unfortunately I don’t think it is possible to set the alarm programatically in android in versions prior to gingerbread (posted a stackoverflow question about it). So the user base is very limited, only users with gingerbread and higher with a LiveView will be able to use it so I don’t expect a massive response. Also I have no idea if this will work with non-stock alarm clock apps as I’m not aware of any manufacturers modification of gingerbread as of yet.
The LiveView application on the phone handles links to all the shared preferences for the plugins (they’re mandatory just for the enable/disable option) but an example is included in all the examples and it is very simple to just add more options to the preferences.xml and grab them in the code.

LiveView plugin settings



Alarm set via plugin
Conc
If you want more info please read the documentation linked at the start of this post. I will probably release the liveview alarm clock plugin onto the market soon, but I don’t expect the reception to be that good as it will only work on a few phones / tablets. Anyway I had fun programming for mine, enjoy!