Issue
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
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()
}
}
Answered By - Android Dev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.