calling javascript function from an android activity

后端 未结 7 1765
心在旅途
心在旅途 2021-01-06 01:13

I wan to call a javascript function from an android activity but it doesn\'t seem to work. I have used the android webview function webview.loadUrl(\"javascript:function()\"

7条回答
  •  生来不讨喜
    2021-01-06 01:50

    Try:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        webview = (WebView)findViewById(R.id.webView1);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl("file:///android_asset/index.html");
        webview.loadUrl("javascript:change("+String.valueOf(i)+")");
    
    }
    

提交回复
热议问题