gpt4 book ai didi

android - 在 WebView 中加载本地 html?

转载 作者:IT王子 更新时间:2023-10-29 00:00:45 26 4
gpt4 key购买 nike

我想在不使用“file:///”的情况下将本地 html 加载到 WebView 中,因为这不允许使用 cookie。有没有办法使用类似“localhost”的东西?

其次,我找不到在 getSettings() 中启用 cookie 的方法。因为使用“file:///”时不允许使用 cookie。

最佳答案

你只能做这样的事情。此解决方案从字符串变量加载 HTML:

String html = "<html><body>Hello, World!</body></html>";
String mime = "text/html";
String encoding = "utf-8";

WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, html, mime, encoding, null);

编辑:尝试设置 loadDataWithBaseURL() 的第一个参数(baseURL)满足您的需求

关于android - 在 WebView 中加载本地 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4543349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com