コード例 #1
0
 @Override
 protected void onDestroy() {
   if (mKlarnaCheckout != null) {
     mKlarnaCheckout.destroy();
   }
   super.onDestroy();
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mStatusText = (TextView) findViewById(R.id.status_text);
    mWebView = (WebView) findViewById(R.id.web_view);
    mWebView.setWebViewClient(getNonRedirectingWebViewClient());

    mKlarnaCheckout = new KlarnaCheckout(this, mWebView);

    mKlarnaCheckout.setSignalListener(
        new SignalListener() {
          private static final String TAG = "SignalListener";

          @Override
          public void onSignal(String eventName, JSONArray jsonArray) {
            Log.d(
                TAG,
                "Got a signal: "
                    + eventName
                    + ", with params: "
                    + (jsonArray != null ? jsonArray.toString() : null));
            mStatusText.setText(eventName);
            if (eventName.equals(EVENT_COMPLETE)) {
              try {

                String url = jsonArray.getJSONObject(0).getString("uri");
                mKlarnaCheckout.getWebView().loadUrl(url);

              } catch (JSONException e) {
                Log.e(TAG, e.getMessage(), e);
              }
            }
          }
        });

    mWebView.loadUrl("https://www.klarnacheckout.com/");
  }