'How to Imbed NiceHash Website Widget into Android App? Would it be WebView?

I would like to put this Profitability calculator from: https://www.nicehash.com/widgets#profcalc

Where the site says to use:

<iframe src="https://widget.nicehash.com/profcalc" width="400" height="350" scrolling="no" id="nhiframe"></iframe>

to "imbed" this widget into your website. Is it possible to put this in an Android app instead? This particular widget? Or would I have to use a webview? I've never done a webview before so I'm not sure how this would all work. Any suggestions would be greatly appreciated!



Solution 1:[1]

I figured it out:

In AndroidManifest.xml: Add inside Application tag:

android:hardwareAccelerated="true"

GPUCalculatorFragment:

onCreateView:
  var webContent = "<iframe src=\"https://widget.nicehash.com/profcalc\" width=\"400\" height=\"350\" scrolling=\"no\" id=\"nhiframe\"></iframe>"

    val calcWebView: WebView = binding.calculatorWebView
    calcWebView.webChromeClient = WebChromeClient()
    calcWebView.webViewClient = WebViewClient()
    calcWebView.settings.javaScriptEnabled = true

    if (webContent.contains("iframe")){
        val matcher = Pattern.compile("src=\\\"([^\\\"]+)\\\"").matcher(webContent)
        matcher.find()

        try {
            calcWebView.loadUrl(matcher.group(1)!!)
        } catch (e: MalformedURLException){
            Toast.makeText(activity, R.string.gpu_fragment_error, Toast.LENGTH_SHORT).show()
            e.printStackTrace()
        }
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Android Dev