Reputation: 347
I'm trying to show an interactive HTML5 page to a user offline using a WebView. Downloaded and unzipped the necessary content and launched the WebView with web.loadUrl("file:///" + uri.toString());
While most of the stuff works there is no audio and LogCat tells me the following:
03-02 17:58:58.082 12066-12205/- D/MediaResourceGetter﹕ canonicalized file path: /data/data/${package.name}/cache/684.unpacked/story_content/video_6kjafYSyahO_30_48_370x208.mp4
03-02 17:58:58.083 12066-12205/- E/MediaResourceGetter﹕ Refusing to read from unsafe file location.`
03-02 17:58:58.083 12066-12205/- E/MediaResourceGetter﹕ Unable to configure metadata extractor
I choose the cache directory because according to the source of MediaResourceGetter this should be a safe location.
This is how i configured my WebView:
WebSettings s = web.getSettings();
s.setBuiltInZoomControls(true);
s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
s.setSavePassword(true);
s.setSaveFormData(true);
s.setJavaScriptEnabled(true);
s.setGeolocationEnabled(true);
s.setGeolocationDatabasePath("/data/data/" + getPackageName() + "/geoloc/");
s.setDomStorageEnabled(true);
s.setJavaScriptEnabled(true);
s.setPluginState(WebSettings.PluginState.ON);
s.setAllowFileAccess(true);
s.setAllowContentAccess(true);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
s.setAllowFileAccessFromFileURLs(true);
s.setAllowUniversalAccessFromFileURLs(true);
}
Upvotes: 1
Views: 1046
Reputation: 6338
Based on source code of getRawAcceptableDirectories
method, WebView should allow to read files from the app cache directory and the sdcard directory.
Upvotes: 1
Reputation:
Thats work me ...
add your html files to "/main/assets/app/" directory
and write code:
w.loadUrl("file:///android_asset/app/YOUR_HTML_FILE_NAME.html");
Upvotes: 0