I am developing an Android native application with WebView. I have used an HTML file to load the WebView and given functionality to the UI elements through javascript by enabling Javascript and adding a Javascript interface.
WebView myWeb=(WebView)findViewById(R.id.webView1);
myWeb.getSettings().setJavaScriptEnabled(true);
myWeb.getSettings().setLoadWithOverviewMode(true);
myWeb.loadUrl("file:///android_asset/webview.html");
myWeb.addJavascriptInterface(new Object()
{
@JavascriptInterface
public void recognizeIt(String message)
{
Toast.makeText(WebViewActivity.this, message,
Toast.LENGTH_LONG).show();
Intent Intent = new Intent(WebViewActivity.this, StartActivity.class);
startActivity(Intent);
}
}, "Android");
below is my html file.
<html>
<head>
<script type="text/javascript">
function shareIt(toast) {
var uname=document.getElementById("message").value;
Android.recognizeIt(uname);
}
</script>
</head>
<body>
<label id="username"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required id="message">
<button type="button" onclick="shareIt('message')"> SEND </button>
</body>
</html>
Now instead of html file, I want to use ReactJS to create UI screens in my app. I tried to search for the same but did not find any samples. I would be very grateful if someone could help / guide me here.