gpt4 book ai didi

java - 带有 WebView 的 Cookie

转载 作者:行者123 更新时间:2023-12-01 17:55:47 25 4
gpt4 key购买 nike

我正在使用 WebView 创建一个仅嵌入显示网站的浏览器的 Android 应用:

mywebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) { ... }
});
mywebView.loadUrl("http://www.example.com");

我注意到两件奇怪的事情:

  • 我收到类似“Cookie 已禁用”的消息

  • 当我点击应显示 PDF 文件的链接时,没有任何反应(但没有错误消息)

如何启用 Cookie 和打开(或至少下载)PDF 文件等功能?

最佳答案

这是一个gist of a small app演示了如何在 WebView 中启用 cookie 以及如何下载/打开 PDF 文件。

请注意,该应用程序演示了打开 PDF 文件的两种方法。第一种方式在WebView中打开PDF;第二种方式在外部应用程序中打开 PDF(如果为 PDF 文件定义了一种方式)。

请务必记住,WebView 不提供成熟的类似浏览器的支持。来自 documentation for WebView :

Basic usage

By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView.

Google 不断完善 WebView,因此您需要及时了解 changes 。此外,Google 继续解决 WebView 的安全问题,例如,将不再支持源自 WebView 的 OAuth 请求。请参阅this .

关于java - 带有 WebView 的 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44980844/

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