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.

CucumberWebView is capable of Javascript SDKs for Ethereum and Tron as follows:

Web3.js
TronWeb

Adding a CucumberWebView to your app

To add a CucumberWebView to your app, you need to 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 (Deprecated)

Add Coin Service Connector

To use a CucumberWebView, your app must run the addCoinServiceConnector.

With CucumberWebView only one Ethereum or Tron account can be received from addCoinServiceConnector when used. onSendTransaction is described below.

// SBlockchain and CoinService initialize code
...
//

WebView webView = view.findViewById(R.id.cucumberWebView);
webView.addCoinServiceConnector(coinType, coinService, account, onSendTransactionListener);

Handle request

Sends a transaction request on the onSendTransaction method. You have to implement the OnSendEthereumTransactionListener or OnSendTronTransactionListener 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.

Ethereum

public class WebViewFragment extends Fragment implements OnSendEthereumTransactionListener{
    ...
    @Override
    public void onSendTransaction(
            String requestId,
            EthereumAccount fromAccount,
            String toAddress,
            BigInteger value,
            String data,
            BigInteger nonce
    ) {
        HardwareWallet connectedHardwareWallet =
                hardwareWalletManager.getConnectedHardwareWallet();
        Intent intent =
                webView.createEthereumPaymentSheetActivityIntent(
                        context,
                        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;
        }

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

Tron

public class WebViewFragment extends Fragment implements OnSendTronTransactionListener{
    ...
    @Override
    public void onSendTransaction(
            String requestId,
            TronPaymentType paymentType,
            TronAccount fromAccount,
            String toAddress,
            BigInteger value,
            String tokenId,
            BigInteger tokenValue,
            String data,
            BigInteger feeLimit
    ) {
        HardwareWallet connectedHardwareWallet =
                hardwareWalletManager.getConnectedHardwareWallet();
        Intent intent = null;

        switch (paymentType) {
            case TRX:
                intent = webView.createTronPaymentSheetActivityIntent(
                        context,
                        requestId,
                        connectedHardwareWallet,
                        fromAccount,
                        toAddress,
                        value
                );
                break;
            case TRC10:
                intent = webView.createTrc10PaymentSheetActivityIntent(
                        context,
                        requestId,
                        connectedHardwareWallet,
                        fromAccount,
                        toAddress,
                        tokenId,
                        tokenValue
                );
                break;
            case SMART_CONTRACT:
                intent = webView.createTronSmartContractPaymentSheetActivityIntent(
                        context,
                        requestId,
                        connectedHardwareWallet,
                        fromAccount,
                        toAddress,
                        data,
                        value,
                        tokenId,
                        tokenValue,
                        feeLimit
                );
                break;
        }

        startActivityForResult(intent, 0);
    }

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

        if (requestCode != 0) {
            return;
        }

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

WebViewClient

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

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