From Html To Native

I write a example from html to native,but it can’t jump.
Here are my code.
H5Activity(html)

webview = (WebView) findViewById(R.id.webview);
        webview.loadUrl("file:///android_asset/hello.html");
        webview.addJavascriptInterface(new Object()
        {
            @JavascriptInterface
            public void jump()
            {
                Intent intent = new Intent(H5Activity.this, NativeBActivity.class);
                startActivity(intent);
            }
        }, "egos");

NativeBActivity(Native)

setContentView(R.layout.activity_nativea);
button = (Button) findViewById(R.id.text);
button.setText("Finish");

my hello.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" /> 
        <script type="text/javascript">
        function flea(){
            // if(egos){
                egos.jump("hello");
            // }
        }
        </script>
    </head>
    <body>
        <p><button onclick="egos.jump()">jump to Native</button></p>
    </body>
</html>

But it doesn’t jump.I try my bes. Can you help me?


Source: html5

Leave a Reply