How to send a notification to Pebble SmartWatch

Hi,

I'm trying to send a notification to my Pebble SmartWatch and therefore have to port this code to Xamarin (Android):

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

//////      
    final Map data = new HashMap();
    data.put("title", "Test Message");
    data.put("body", "Whoever said nothing was impossible never tried to slam a revolving door.");
    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);
    }

I'm not able to port the stuff between the "/////".

Anyone who can help?

Cheers
Frank

Posts

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    notificationData is a string containing a JSON array containing a JSON dictionary. Use System.Json.dll (or JSON.net, or string.Format(), or...) to create a similar JSON structure.

    I'm no JSON expert, but I imagine that notificationData will look something like:

    string notificationData = @"[
        { ""title"": ""Test Message"",
          ""body"": ""Whoever said nothing was impossible never tried to slam a revolving door."" }
    ]";
    
  • It works!

            private void sendAlertToPebble(System.String msgBody) 
            {
                var i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
                string notificationData = @"[{""title"":""Test Message"",""body"":"""[email protected]"""}]";
                i.PutExtra("messageType", "PEBBLE_ALERT");
                i.PutExtra("sender", "FSHBT");
                i.PutExtra("notificationData", notificationData);
                Log.Debug(TAG, "About to send a modal alert to Pebble: " + notificationData);
                SendBroadcast(i);
            }
    
  • ColinBrownColinBrown GBMember ✭✭

    Hi Frank,

    I'm looking at developing a Android app for Pebble using Xamarin. Do you have any code based on the above that you can share? Looks like you got on pretty well!

    Thanks,
    Colin.

  • redickchenredickchen USMember
    edited June 2014

    @‌ Frank ,
    I want to develop some apps on my Nexus 5 that can communicate with my pebble, But I'm a new for Xamarin. Can you tell me how can I get start?
    Thanks.

  • redickchenredickchen USMember

    @‌Frank , I want to develop some apps on my Nexus 5 that can communicate with my pebble, But I'm a new for Xamarin. Can you tell me how can I get start? Or how can I use the SDK in Xamarin by binding?

  • redickchenredickchen USMember

    @FrankSchmidberger
    Any assistance or materials would be greatly appreciated. Thanks.

Sign In or Register to comment.