Cucumber WebView

CucumberWebview is specialized for WebView for the Web Dapp. You can integrate your Web Dapp into mobile.

The Blockchain Platform SDK provides the CucumberWebView for android WebView. For further android WebView information, see https://developer.android.com/guide/webapps.

For ethereum, capability and support Web3.js you can get information by going to .

Adding a CucumberWebView to your app

To add a CucumberWebView to your app, you add a component in the layout.

<com.samsung.android.sdk.blockchain.ui.CucumberWebView
    android:id="@+id/cucumberWebView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
/>

Initialize Cucumber WebView

To use a CucumberWebView, your app must run the initialize code when view is created.

With CucumberWebViewm only one ethereum account can be received from init when used. onSendTransaction is described below.

// SBlockchain and EthereumService initialize code
...
//

mWebView = view.findViewById(R.id.cucumberWebView);
mWebView.init(mEthService, mEthAccount, this::onSendTransaction);

Handle request

Sends a transaction request on the OnSendTransactionListener.onSendTransaction method. You have to implement the OnSendTransactionListener to complete the request. You have to handle the request with onSendTransaction. A simpler way to handle the request is to use the PaymentSheet.

When the processing is completed, the result must be sent to the WebView. onActivityResult must be overrided including the CucumberWebView.onActivityResult.

public class WebViewFragment extends Fragment implements OnSendTransactionListener{
    ...
    @Override
    public void onSendTransaction(
            @NotNull String requestId,
            @NotNull EthereumAccount fromAccount,
            @NotNull String toAddress,
            @org.jetbrains.annotations.Nullable BigInteger value,
            @org.jetbrains.annotations.Nullable String data,
            @org.jetbrains.annotations.Nullable BigInteger nonce
    ) {
        HardwareWallet connectedHardwareWallet =
                mHardwareWalletManager.getConnectedHardwareWallet();
        Intent intent =
                mWebView.createEthereumPaymentSheetActivityIntent(
                        mOwnerActivity,
                        requestId,
                        connectedHardwareWallet,
                        toAddress,
                        value,
                        data,
                        nonce
                );

        startActivityForResult(intent, 0);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode != 0) {
            return;
        }

        mWebView.onActivityResult(requestCode, resultCode, data);
    }

WebViewClient

CucumberWebView uses the CucumberWebViewClient. If you want to use your WebViewClient, you have to inherit CucumberWebViewClient class.

We do not recommend the Override shouldOverrideUrlLoading and shouldInterceptRequest method. If you have to override using these methods, you have to call the super method.

mWebView = view.findViewById(R.id.cucumberWebView);
try {
    mWebView.setWebViewClient(customWebViewClient);
}catch(IllegalArgumentException e){
    //customWebViewClient is not a CucumberWebViewClient
}