Pebble

Pebble is a customizable, Bluetooth-enabled smartwatch that connects to iPhone and Android smartphones. It features a 144×168 1-bit display, a 3-axis accelerometer and a Cortex-M3 ARM microprocessor. Pebble can be customized by installing new apps developed with its Software Development Kit. The SDK allows developers of all experience levels to build Pebble-enabled applications using a number of popular programming languages and technologies.

This document is a work in progress

This document is an early preview of Pebble's Android SDK and represents a point-in-time snapshot of our rapidly evolving APIs. All SDK details are subject to change prior to Pebble's release. If you wish to be notified of upcoming changes to the Pebble SDK, please subscribe to our developer mailing list.

We're hard at work to deliver a first-class experience for developers building Pebble-enabled applications. If you'd like to receive updates as we continue to build Pebble's SDK, please join our official developer mailing list.

Subscribe

All communication between Pebble and an Android device is managed through a local Android service (Pebble Service) installed on the smartphone. Pebble Service leverages Android's intent messaging system for bi-directional communication between Android devices and Pebble, making it easy for developers to add optional support for Pebble to pre-existing Android applications.

The following data can be exchanged between Pebble and an Android device via intent messages:

  1. Push pre-formatted notifications to Pebble using one of several built-in message types (including alarms, text messages, speedometer data and modal notification boxes)
  2. Push data to Pebble for processing by native code
  3. Receive data from native code running on Pebble
  4. Receive notifications when Pebble becomes connected/disconnected

Send Notification to Pebble

Description
Send pre-formatted notifications to be displayed by Pebble's built-in notification app.
Action
com.getpebble.action.SEND_NOTIFICATION
Extras
  • String messageType — An enum that identifies the type of message being sent to the Pebble
  • String sender — A String that uniquely identifies the application sending a message to Pebble
  • String notificationData — A JSON representation of the data specific to the messageType.

Example — Sending a modal 'alert' message to Pebble

public void sendAlertToPebble() {
    final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");

    final Map<String, Object> data = new HashMap<String, Object>();
    data.put("title", getAlertTitle());
    data.put("body", getAlertBody());
    final JSONObject jsonData = new JSONObject(data);
    final String notificationData = new JSONArray().put(jsonData).toString();

    i.putExtra("messageType", PEBBLE_ALERT);
    i.putExtra("sender", "MyAndroidApp");
    i.putExtra("notificationData", notificationData);

    Log.d(TAG, "About to send a modal alert to Pebble: " + notificationData);
    sendBroadcast(i);
}

Send Data to Pebble

Description
Send UTF-8 data to Pebble to be consumed by a native watch-app.
Action
com.getpebble.action.SEND_DATA
Extras
  • String sender — A String that uniquely identifies the application sending a message to Pebble
  • String recipient — A String that unique identifies the intended recipient of the data. Messages addressed to an unregistered recipient will be ignored by Pebble.
  • String data — A UTF-8 payload to be sent to the watch. Out-bound message size is capped at 4k. Larger messages will be silently discarded before being sent to Pebble.

Example — Sending location coordinates to a geocaching app on Pebble

public void sendLocationInfoToPebble() {
    final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (location == null)
        return;

    final String latLong = String.format("%.02f %.02f",
            location.getLatitude(),
            location.getLongitude());

    final Intent i = new Intent("com.getpebble.action.SEND_DATA");
    i.putExtra("sender", "MyGeocachingApp");
    i.putExtra("recipient", "PebbleGeocache");
    i.putExtra("data", latLong);

    Log.d(TAG, "About to send location coordinates to Pebble: " + latLong);
    sendBroadcast(i);
}

Receive Data from Pebble

Description
This intent is broadcast upon receiving data pushed from Pebble to an Android device.
Action
com.getpebble.action.RECEIVE_DATA
Extras
  • String sender — A String that uniquely identifies the watch-app sending data to the Android device.
  • String recipient — A String that uniquely identifies the Android application intended to receive the data.
    Applications that receive data from Pebble must perform additional filtering to ensure that they do not process data addressed another application.
  • String data — The payload received from Pebble. In-bound message size is capped at 4k.

Example — Responding to pause/resume commands from Pebble

public class SportsAppBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent inboundIntent) {
        final String pebbleRecipient = inboundIntent.getStringExtra("recipient");
        if (! "MyApp".equals(pebbleRecipient))
            return;

        final String pebbleData = inboundIntent.getStringExtra("data");

        if ("PauseResume".equals(pebbleData)) {
            toggleActivityTimerPause();
        }
    }
}

Receive a Notification When Pebble is Connected

Description
This intent is broadcast when the Android device establishes a new Bluetooth connection to Pebble.
Action
com.getpebble.action.PEBBLE_CONNECTED
Extras
  • String address — A String representation of Pebble's Bluetooth MAC address.

Example — Listening for 'Pebble connected' messages

 public class PebbleConnectionReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        final String pebbleAddress = intent.getStringExtra("address");
        Log.i(TAG, "Pebble (%s) connected", pebbleAddress);
    }
}

Receive a Notification When Pebble is Disconnected

Description
This intent is broadcast when the Android device loses its Bluetooth connection to Pebble.
Action
com.getpebble.action.PEBBLE_DISCONNECTED
Extras
  • String address — A String representation of Pebble's Bluetooth MAC address.

Example — Listening for 'Pebble disconnected' messages

public class PebbleConnectionReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        final String pebbleAddress = intent.getStringExtra("address");
        Log.i(TAG, "Pebble (%s) disconnected", pebbleAddress);
    }
}