How do you load Javascript into android webview?

Seaborn Lee picture Seaborn Lee · Apr 18, 2013 · Viewed 8.9k times · Source

HTML code:

<!DOCTYPE html>
    <html>
        <head>
            <script src="resource://jquery.min.js"></script>
        </head>
        <body>
        </body>
    </html>

I want to intercept the protocol(resource://) and manual load Javascript into the webview. So I can store third party libs in android assets.

I tried override onLoadResource of WebViewClient and then use webView.loadData(data, mimeType, encoding); But it didn't work because the app went into a endless loop.

Answer

Seaborn Lee picture Seaborn Lee · Apr 19, 2013

Found the answer, and it works perfectly! I have searched this question many times via google and stackoverflow but haven't got the right answer. And finally my roommate made it happen with just the first trying.

Android WebView Javascript from assets