Reputation: 1473
I'm creating a very simple pebble app.
Goal: When I click on my Android app, for the Pebble app to display the message I'm sending from my Android app.
Issue: Text does not change/display on the pebble.
Code
Pebble .c code:
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x98, 0x15, 0xA8, 0xDA, 0x6C, 0xAC, 0x40, 0xB0, 0xAD, 0x87, 0xFC, 0xDF, 0x9E, 0x86, 0x3E, 0x91 }
PBL_APP_INFO(MY_UUID,
"Phone App", "Me",
1, 0, /* App version */
DEFAULT_MENU_ICON,
APP_INFO_STANDARD_APP);
Window window;
TextLayer hello_layer;
AppMessageCallbacksNode messageCallBacks;
void myMessageHandler(DictionaryIterator* received, void* context) {
vibes_short_pulse();
Tuple* tuple = dict_find(received, 0);
text_layer_set_text(&hello_layer, tuple->value->cstring);
}
void handle_init(AppContextRef ctx) {
messageCallBacks = (AppMessageCallbacksNode) {
.callbacks = {
.in_received = myMessageHandler
},
.context = NULL
};
window_init(&window, "Window Name");
window_stack_push(&window, true /* Animated */);
text_layer_init(&hello_layer, GRect(0, 65, 144, 30));
text_layer_set_text(&hello_layer, "Hello World!");
layer_add_child(window_get_root_layer(&window), (Layer*)&hello_layer);
}
void pbl_main(void *params) {
PebbleAppHandlers handlers = {
.init_handler = &handle_init,
.messaging_info = {
.buffer_sizes = {
.inbound = 64,
.outbound = 64
}
}
};
app_event_loop(params, &handlers);
}
Android Code:
public class MainActivity extends Activity {
private Button send;
private Context context;
UUID AppId = UUID
.fromString("9815A8DA-6CAC-40B0-AD87-FCDF9E863E91");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send = (Button) findViewById(R.id.send);
context = this;
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
PebbleDictionary data = new PebbleDictionary();
data.addString(0, "TEST");
PebbleKit.sendDataToPebble(getApplicationContext(), AppId, data);
}
});
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Thank you!
Upvotes: 0
Views: 420
Reputation: 4675
It looks like you are missing a call to app_message_register_callbacks
in your handle_init
method.
Adding this should do the trick:
app_message_register_callbacks(&messageCallBacks);
You are still using SDK 1.x which is now deprecated. I strongly recommend that you upgrade to SDK 2.0. The development and debugging tools are much nicer. You will also have way more APIs to play with.
Upvotes: 1