在WebVIew中使用脱机样式表

时间:2012-03-20 18:03:09

标签: android webview css

如果没有互联网连接,我想使用临时下载的样式表。

<link rel=\"stylesheet\" type=\"text/css\" href=\"MY_HREF">

如果我使用“href = file:///android_asset/stylesheet.css”,它可以使用打包文件,但这是不可交换的。

我想使用像file:///data/data/cache/stylesheet.css这样的东西。 WebSettings.setAllowFileAccess(true)没有帮助。

我已经尝试了内容://my.authority/stylesheet.css并为my.authority实现了我自己的ContentProvider。

ContentProvider实现openFile并由WebView调用: 我已经检查过,该文件确实存在。

@Override
    public ParcelFileDescriptor openFile(Uri uri, String mode)
            throws FileNotFoundException {
        String path = uri.getEncodedPath();
        return ParcelFileDescriptor.open(new File(getContext().getCacheDir(), path), ParcelFileDescriptor.MODE_WORLD_READABLE);
    }

这显示在日志中:“webview:例外:content://my.authority/stylesheet.css

有什么建议吗?

0 个答案:

没有答案