Hello All,
I have been looking at the Pebble Watch documentation (which only contains few methods for now) and was wondering how to do it in B4A. At the moment the pebble watch can only be communicated by sending intents to the pebble android app.
Can anyone help please with the following?
Send Notification to Pebble
Send Data to Pebble
Receive Data from Pebble
Receive a Notification When Pebble is Connected
Receive a Notification When Pebble is Disconnected
Thank you.
I have been looking at the Pebble Watch documentation (which only contains few methods for now) and was wondering how to do it in B4A. At the moment the pebble watch can only be communicated by sending intents to the pebble android app.
Can anyone help please with the following?
Send Notification to Pebble
B4X:
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
B4X:
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
B4X:
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
B4X:
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
B4X:
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);
}
}
Thank you.