1
votes

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.

1
Why not just use file:///android_asset URLs instead? - CommonsWare
I'd suggest reading through the PhoneGap (Now Cordova) source code. They've been doing this for a while now. - jmcdale
@jamn224 I tested phonegap but it does't work. I move the index.html to my web server and modify the script tag like this: <script type="text/javascript" src="file:///android_asset/www/cordova-2.6.0.js"></script> - Seaborn Lee

1 Answers

1
votes

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