Access a local file in WebView

My native application has a WebView, and WebView downloads a webpage from the Internet. For example, html is loaded from

http://dongshengcn.com/test.html

It seems that any page downloaded from the Internet (instead of the local one) cannot download any file from the local device.

My question is:

Is it possible that http://dongsheng.com/test.html is uploaded to the webview (as part of its own application) to access the file on the local device?

+3
source share
1 answer

Here are a few things to try:

  • , URL-, :///android_asset/. , mypage.html , webview :///android_asset/mypage.html.

  • , - . - , :

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

  • Github, - Honeycomb ICS. , - : https://github.com/bricolsoftconsulting/WebViewIssue17535FixDemo

EDIT: :

, , , .

://android_asset/ URL- (, ///android _asset/mypage.html myscheme:///mypage.html) URL- , WebViewClient shouldOverrideUrlLoading, , URL webview.loadUrl.

    mWebView.setWebViewClient(new WebViewClient()  
    {  
        @Override  
        public boolean shouldOverrideUrlLoading(WebView view, String url)  
        {  
            if (url != null && url.startsWith("myscheme://"))  
            {  
                String newUrl = url.replace("myscheme://", "file://android_asset/");  
                mWebView.loadUrl(newUrl);  
                return true;  
            }  
            return false;  
        }  
    }  
+3

All Articles