Issue
I have created a javascript script and would like to run it in a webview in my android app. How do I go about doing this so when the user clicks on the money button the javascript runs.
Code Below
Javascript
<script type="text/javascript" src="https://static.leaddyno.com/js"></script>
<script>
LeadDyno.key = "hg5kjh5j4h6jhjhjkk7hjhjhjkh56vhjfgcg4gjd";
LeadDyno.recordVisit();
LeadDyno.autoWatch();
</script>
Button Click
btnMoney.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Run Javascript
myWebView.loadUrl("javascript:LeadDyno.recordVisit()");
myWebview2.loadUrl("javascript.LeadDyno.autoWatch()");
}
});
Solution
- create assets folder in app/src/main;
- create a new file html.html;
- add your javascript code into html.html;
load it by webview like:
webview.load("file:///android_asset/html.html");
Do not forget to add android.permission.INTERNET in your manifest file
Answered By - aolphn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.