Send a Message to Pebble Watch using Android App

You can send a message from your Android app to a connected Pebble watch. We will use PebbleKit Android, the library that enables communication with Pebble. To use it, add PebbleKit to your list of dependencies in the dependencies block (add this if it does not already exist):

dependencies {
  // ...
  compile 'com.getpebble:pebblekit:3.0.0'

Once the dependanceis are resolved you can use the following method to send a message to the watch. The SendMessage method accepts title and body as parameters and does the following.

  • It first checks if the watch is connected
  • If the watch is connected then it created a new Intent
  • Next it add the data to be sent to a Map
  • Finally it sends the intent as a broadcast using sendBroadcast(i)
public void SendMessage(String title, String body)
    // Is the watch connected?
    boolean isConnected = PebbleKit.isWatchConnected(this);

    if(isConnected) {
        // Push a notification
        final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");

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

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

To learn more about integrating Android app with Pebble head over to Pebble’s Developer Guide.

This content has been helpful to you?

Thanks for contributing!

Yes No