非常にシンプルな小石アプリを作成しています。
目標: Android アプリをクリックすると、Android アプリから送信したメッセージが Pebble アプリに表示されます。
問題: 小石のテキストが変更/表示されません。
コード
小石 .c コード:
#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 コード:
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;
}
}
ありがとうございました!