Пример #1
0
  /**
   * Load an URL in the device's browser application.
   *
   * @param args JSONArry of arguments for the action.
   * @return a PluginResult
   */
  private PluginResult openExternal(JSONArray args) {
    try {
      String url = args.getString(0);

      BrowserSession session = Browser.getDefaultSession();
      session.displayPage(url);
    } catch (JSONException e) {
      return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }

    return new PluginResult(PluginResult.Status.OK, "");
  }
Пример #2
0
  /**
   * Display the specified URL in a custom browser screen.
   *
   * @param args JSONArry of arguments for the action.
   * @return a PluginResult
   */
  private synchronized PluginResult showWebPage(JSONArray args) {
    PluginResult result;

    if (browser == null) {
      try {
        boolean showLocationBar = true;
        String url = args.getString(0);
        JSONObject options = args.getJSONObject(1);

        // Determine whether to show or hide navigation bar.
        if (options != null) {
          showLocationBar = options.optBoolean("showLocationBar", true);
        }

        browser = new CustomBrowser(callbackId);
        if (browser.init(showLocationBar)) {
          uiApp.invokeLater(
              new Runnable() {
                public void run() {
                  uiApp.pushScreen(browser);
                }
              });

          browser.loadURL(url);

          // Must keep the callback for browser URL load and close
          // events.
          result = new PluginResult(PluginResult.Status.OK, "");
          result.setKeepCallback(true);
        } else {
          result =
              new PluginResult(
                  PluginResult.Status.ERROR, TAG + "Failed to initialize CustomBrowser.");
        }
      } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
      }
    } else {
      result = new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open.");
    }

    return result;
  }