Reputation: 46353
I'm creating an Android app embedding just a browser displaying a website, using WebView
:
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");
I noticed two strange things:
I get a message like "Cookies are disabled"
When I click on links that should display PDF files, nothing happens (but no error message)
How to enable features like cookies and opening (or at least downloading) PDF files?
Upvotes: 0
Views: 1037
Reputation: 62841
Here is a gist of a small app that demonstrates how to enable cookies in WebView and how to download/open a PDF file.
Note that the app demonstrates two ways of opening a PDF file. The first way opens the PDF within WebView; the second way opens the PDF in an external app if one is defined for PDF files.
It is important to remember that WebView
does not offer full-blown browser-like support. From the 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 continues to refine WebView
, so you will want to keep abreast of changes. In addition, Google continues to address the security of WebView
and, for instance, will no longer support OAuth requests originating from a WebView
. See this.
Upvotes: 4