0

线路本身有任何提示吗?我看不到日志,因为我的防火墙不允许我与设备通信,并且您必须安装 pbw。

我也不明白为什么路径在 FileNotFoundException 中重复

这是我在 android 监视器中的错误日志:

    05-26 16:42:46.918: D/PebbleWebappBaseActivity(1092): [JsKit::com.getpebble.android.ui.webapps.PebbleBabel$AppInfoBlocks@428e3a98] : appInfoJsonString: {"resources":{"media":[]},"versionLabel":"1.0.0","watchapp":{"watchface":true},"appKeys":{"location":0},"longName":"findAB","versionCode":1,"capabilities":["location"],"uuid":"bec76309-db1b-4382-9881-be301ae94752","companyName":"GFT","shortName":"findAB"}
    05-26 16:42:46.938: D/WebView DEBUG(1092): onPageFinished: file:///android_asset/jskit_startup.html?params=%7B%22loadUrl%22%3A%22file%3A%5C%2F%5C%2F%5C%2Fdata%5C%2Fdata%5C%2Fcom.getpebble.android%5C%2Fapp_jskit_installed_apps%5C%2FfindAB__1%5C%2Fpebble-js-app.js%22%7D
    05-26 16:42:46.938: E/EXCEPTION(1092): Exception:java.io.FileNotFoundException: /data/data/com.getpebble.android/app_jskit_installed_apps/findAB__1/data/data/com.getpebble.android/app_jskit_installed_apps/findAB__1/pebble-js-app.js: open failed: ENOENT (No such file or directory)
    05-26 16:42:46.938: E/EXCEPTION(1092):  at libcore.io.IoBridge.open(IoBridge.java:409) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at java.io.FileInputStream.<init>(FileInputStream.java:78) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at com.getpebble.android.ui.webapps.WebappSupport.inputStreamForResource(WebappSupport.java:590) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at com.getpebble.android.ui.webapps.JsKit.handleLocalResourceLoadByWebapp(JsKit.java:349) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at com.getpebble.android.ui.webapps.WebappSupport$CustomWebViewClient.shouldInterceptRequest(WebappSupport.java:802) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at com.android.webview.chromium.WebViewContentsClientAdapter.shouldInterceptRequest(WebViewContentsClientAdapter.java:277) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at com.android.org.chromium.android_webview.AwContents$IoThreadClientImpl.shouldInterceptRequest(AwContents.java:249) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at dalvik.system.NativeStart.run(Native Method) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
    05-26 16:42:46.938: E/EXCEPTION(1092):  at libcore.io.Posix.open(Native Method) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  at libcore.io.IoBridge.open(IoBridge.java:393) ~[na:0.0]
    05-26 16:42:46.938: E/EXCEPTION(1092):  ... 7 common frames omitted
    05-26 16:42:46.938: D/PebbleJS(1092): findAB:372 signalLoaded
    05-26 16:42:46.938: D/PebbleJS(1092): findAB:374 inside try-bridge-active
    05-26 16:42:46.938: D/PebbleJS(1092): findAB:387 registerWebapp() failed; no such function embedded in your .js code(system will now attempt default native-mode register
    05-26 16:42:46.948: D/PebbleWebappBaseActivity(1092): [JsKit::com.getpebble.android.ui.webapps.PebbleBabel$AppInfoBlocks@428e3a98] : appInfoJsonString: {"resources":{"media":[]},"versionLabel":"1.0.0","watchapp":{"watchface":true},"appKeys":{"location":0},"longName":"findAB","versionCode":1,"capabilities":["location"],"uuid":"bec76309-db1b-4382-9881-be301ae94752","companyName":"GFT","shortName":"findAB"}
    05-26 16:42:46.948: E/EXCEPTION(1092): Exception:java.lang.NullPointerException: null
    05-26 16:42:46.948: E/EXCEPTION(1092):  at com.getpebble.android.ui.ManageWatchappsFragment.access$300(ManageWatchappsFragment.java:28) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at com.getpebble.android.ui.ManageWatchappsFragment$3.run(ManageWatchappsFragment.java:315) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at android.os.Handler.handleCallback(Handler.java:733) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at android.os.Handler.dispatchMessage(Handler.java:95) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at android.os.Looper.loop(Looper.java:136) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at android.app.ActivityThread.main(ActivityThread.java:5017) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at java.lang.reflect.Method.invokeNative(Native Method) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at java.lang.reflect.Method.invoke(Method.java:515) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) ~[na:0.0]
    05-26 16:42:46.948: E/EXCEPTION(1092):  at dalvik.system.NativeStart.main(Native Method) ~[na:0.0]
    05-26 16:42:46.948: D/PebbleJS(1092): findAB:399 signalLoaded (finalized)

这是json:

    {
      "uuid": "bec76309-db1b-4382-9881-be301ae94752",
      "shortName": "findAB",
      "longName": "findAB",
      "companyName": "GFT",
      "versionCode": 1,
      "versionLabel": "1.0.0",
      "watchapp": {
        "watchface": true
      },
      "appKeys": {
        "location": 0
      },
      "resources": {
        "media": []
      },
      "capabilities": [
          "location"
      ]
    }

这是js:

    var locationOptions = {
        timeout: 15000,
        maximumAge: 60000
    };

    function fetch_location_data(pos) {
        var req = new XMLHttpRequest(),
                version = Date.now();


        params = toParams(pos);
        req.setRequestHeader("Content-type", "application/json");
        req.setRequestHeader("Content-length", params.length);
        req.setRequestHeader("Connection", "close");
        req.open('POST', "https://apersebank.gtbs.com/org-appverse-app-banking/rest/other/branches/find", true);

        req.onload = function(e) {
            if (req.readyState == 4 && req.status == 200) {
                if (req.status == 200) {
                    var response = JSON.parse(req.responseText);

                    if (response && response.meta.code == '200' && response.response) {
                        var venue = response.response.venues[0];

                        Pebble.sendAppMessage({
                            location: venue.location.address + ', ' + venue.location.city
                        }, function(e) {
                            console.log("Successfully delivered message with transactionId=" + e.data);
                        }, function(e) {
                            console.log("Unable to deliver message with transactionId=" + e.data + ". Error is: " + e.error.message);
                        });
                    }
                } else {
                    console.log('Error');
                }
            }
        }

        req.send(params);
    }

    function toParams(pos) {a
        var latitude = pos.coords.latitude,
                longitude = pos.coords.longitude;
        return "{'latitude':" + latitude + ",'longitude':" + longitude + ",'radius':10}"
    }

    function fetch_location_error(err) {
        console.log(err);
        Pebble.sendAppMessage({
            location: 'Unable to retrieve location'
        });
    }

    Pebble.addEventListener('ready', function(e) {
        locationWatcher = window.navigator.geolocation.watchPosition(fetch_location_data, fetch_location_error, locationOptions);
    });

这是我认为是问题的.c,但完全不确定

#include <pebble.h>

static Window *window;
static TextLayer *text_layer;
static TextLayer *label_layer;
static TextLayer *time_layer;

static AppSync sync;
static uint8_t sync_buffer[64];

enum {
    OUR_LOCATION = 0x0
};

void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) {

    switch (key) {
        case OUR_LOCATION:
            text_layer_set_text(text_layer, new_tuple->value->cstring);
            break;
    }
}

// http://stackoverflow.com/questions/21150193/logging-enums-on-the-pebble-watch/21172222#21172222
char *translate_error(AppMessageResult result) {
    switch (result) {
        case APP_MSG_OK: return "APP_MSG_OK";
        case APP_MSG_SEND_TIMEOUT: return "APP_MSG_SEND_TIMEOUT";
        case APP_MSG_SEND_REJECTED: return "APP_MSG_SEND_REJECTED";
        case APP_MSG_NOT_CONNECTED: return "APP_MSG_NOT_CONNECTED";
        case APP_MSG_APP_NOT_RUNNING: return "APP_MSG_APP_NOT_RUNNING";
        case APP_MSG_INVALID_ARGS: return "APP_MSG_INVALID_ARGS";
        case APP_MSG_BUSY: return "APP_MSG_BUSY";
        case APP_MSG_BUFFER_OVERFLOW: return "APP_MSG_BUFFER_OVERFLOW";
        case APP_MSG_ALREADY_RELEASED: return "APP_MSG_ALREADY_RELEASED";
        case APP_MSG_CALLBACK_ALREADY_REGISTERED: return "APP_MSG_CALLBACK_ALREADY_REGISTERED";
        case APP_MSG_CALLBACK_NOT_REGISTERED: return "APP_MSG_CALLBACK_NOT_REGISTERED";
        case APP_MSG_OUT_OF_MEMORY: return "APP_MSG_OUT_OF_MEMORY";
        case APP_MSG_CLOSED: return "APP_MSG_CLOSED";
        case APP_MSG_INTERNAL_ERROR: return "APP_MSG_INTERNAL_ERROR";
        default: return "UNKNOWN ERROR";
    }
}

void sync_error_callback(DictionaryResult dict_error, AppMessageResult app_message_error, void *context) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "... Sync Error: %s", translate_error(app_message_error));
}

static void handle_second_tick(struct tm* tick_time, TimeUnits units_changed) {
    static char time_text[] = "00:00";

    strftime(time_text, sizeof(time_text), "%I:%M", tick_time);
    text_layer_set_text(time_layer, time_text);
}

static void init_clock(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);

    time_layer = text_layer_create(GRect(0, 20, bounds.size.w, bounds.size.h-100));
    text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
    text_layer_set_text_color(time_layer, GColorWhite);
    text_layer_set_background_color(time_layer, GColorClear);
    text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT));

    time_t now = time(NULL);
    struct tm *current_time = localtime(&now);
    handle_second_tick(current_time, SECOND_UNIT);
    tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);

    layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));
}

static void init_location_search(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);

    label_layer = text_layer_create((GRect) { .origin = { 0, 90 }, .size = { bounds.size.w, 100 } });
    text_layer_set_text(label_layer, "Nearest Office:");
    text_layer_set_text_color(label_layer, GColorWhite);
    text_layer_set_text_alignment(label_layer, GTextAlignmentCenter);
    text_layer_set_background_color(label_layer, GColorClear);
    text_layer_set_font(label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
    layer_add_child(window_layer, text_layer_get_layer(label_layer));

    text_layer = text_layer_create((GRect) { .origin = { 0, 115 }, .size = { bounds.size.w, bounds.size.h } });
    text_layer_set_text(text_layer, "Loading...");
    text_layer_set_text_color(text_layer, GColorWhite);
    text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
    text_layer_set_background_color(text_layer, GColorClear);
    text_layer_set_overflow_mode(text_layer, GTextOverflowModeFill);
    text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
    layer_add_child(window_layer, text_layer_get_layer(text_layer));

    Tuplet initial_values[] = {
        TupletCString(OUR_LOCATION, "Loading...")
    };

    app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL);
}

static void window_load(Window *window) {
    init_location_search(window);
    init_clock(window);
}

static void window_unload(Window *window) {
    text_layer_destroy(text_layer);
    text_layer_destroy(label_layer);
    text_layer_destroy(time_layer);
}

static void init(void) {
    window = window_create();
    window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
    });

    app_message_open(64, 64);

    const bool animated = true;
    window_stack_push(window, animated);
    window_set_background_color(window, GColorBlack);
}

static void deinit(void) {
    window_destroy(window);
}

int main(void) {
    init();

    APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", window);

    app_event_loop();
    deinit();
}
4

1 回答 1

0

Finally I achieved to connect the pebble directly and be able to watch the logs... all the problem was in the JS :

params = toParams(pos);
req.setRequestHeader("Content-type", "application/json");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.open('POST', "https://apersebank.gtbs.com/org-appverse-app-banking/rest/other/branches/find", true);

I was trying to set headers before opening the req obj, now it's working:

params = toParams(pos);
req.open('POST', "https://apersebank.gtbs.com/org-appverse-app-banking/rest/other/branches/find", true);
req.setRequestHeader("Content-type", "application/json");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
于 2014-05-28T07:06:10.580 回答