示例#1
0
  public SessionPackage getSessionPackage(Context context) {
    String preloader = "Error...";
    try {
      preloader = IOUtils.toString(context.getResources().openRawResource(R.raw.loading));
    } catch (NotFoundException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    try {
      LoginPackage lp = preLogin();
      if (lp == null) {
        throw new BankException(
            "No automatic login for this bank. preLogin() is not implemented or has failed.");
      }
      // TODO: Skip the form submission. Login using Bank.login(...) and transfer cookies to
      // webview. The user is now logged in
      //      and can me directed to any page.
      String html =
          String.format(
              preloader,
              "function go(){document.getElementById('submitform').submit(); }", // Javascript
                                                                                 // function
              Helpers.renderForm(lp.getLoginTarget(), lp.getPostData())
                  + "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>" // HTML
              );

      CookieStore cookies = urlopen.getHttpclient().getCookieStore();
      return new SessionPackage(html, cookies);
    } catch (ClientProtocolException e) {
      Log.e(TAG, e.getMessage());
    } catch (IOException e) {
      Log.e(TAG, e.getMessage());
    } catch (BankException e) {
      Log.e(TAG, e.getMessage());
    }
    String html =
        String.format(
            preloader,
            String.format(
                "function go(){window.location=\"%s\" }", this.URL), // Javascript function
            "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>" // HTML
            );
    return new SessionPackage(html, null);
  }