delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

Load html pages from sdcard #172

Closed complitech closed 6 years ago

complitech commented 6 years ago

Hi, is there a way to load html file from sdcard ?

Like, mWebView.loadUrl("file:///android_asset/index.html");

I tried with following code but its not loading my html page :

mWebView.loadUrl("file://" + file.getAbsolutePath());

ocram commented 6 years ago

Did you check Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)?

What value does file.getAbsolutePath() return?

What does Environment.getExternalStorageDirectory() give you?

complitech commented 6 years ago

Hi @ocram

Yea media mounted true.

Here is path for my file : mWebView.loadUrl("file:///storage/emulated/0/hensler_bone_press/index.html");

complitech commented 6 years ago

Hello,

I solved it by following way :

mWebView = (AdvancedWebView) findViewById(R.id.webview);
 mWebView.getSettings().setAllowFileAccess(true);
 mWebView.loadUrl("file:///" + "sdcard/Android/data/android.webview.demo/abc/index.html");

Thanks for your response. (Y)

ocram commented 6 years ago

Glad you found a solution, and thanks a lot for sharing it!

This has now been added to the README so others will find it more easily in the future: https://github.com/delight-im/Android-AdvancedWebView/commit/e347b203b0b89498d7fb72099e21240ecbb3f11f