开发者

How do I reference a file stored in internal storage from a WebView?

I have some files stored in the app's "internal storage", which is located on the device here:

/data/data//files/

Here's the problem: I want to reference these files from the webview. How do I do this? What should I use as the baseUrl?

I need something similar to file:///android_asset but for "internal storage" instead开发者_运维问答 of for files in the assets directory.


Try this:

file:///data/data/com.yourproject.example/files/image.png


You should use Context.getFilesDir() when generating the path, not hard coding the application's files-path. This will ensure that the application will still work even if your package/namespace changes.

Example:

String filesPath = getFilesDir().getAbsolutePath();
String filePath = "file://" + filesPath + "/image.png";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜