I am using a WebView to display this feedburner. When I view this link in Google Chrome and in the device's browser it shows the title, snippet, links, and most importantly a podcast file and other hyperlinks. However, when I view this link in my WebView it only shows it in Plain Text HTML with no hyperlinks. All i see is a title and the story snippet, followed by HTML source code. Is there a particular that must be enabled to resolve this?
These are my WebView settings:
newsfeed = (WebView) findViewById(R.id.webViewnews);
newsfeed.getSettings().setJavaScriptEnabled(true);
newsfeed.setVerticalScrollBarEnabled(false);
newsfeed.getSettings().setPluginsEnabled(true);
How I load the URL:
try {
newsfeed.loadUrl("http://feeds.feedburner.com/fsn");
} catch (Exception e) {
e.printStackTrace();
}
I'm seeing what you are seeing, list of entries with Title followed by html of article content on the Stock Browser - Motorola Droid running 2.2.3. My guess is that this is the format that the site provided for the stock Android WebView User Agent. Google Chrome is NOT the stock browser that comes with Android Open Source Project and does more under the hood to render content.
I would try a different user agent first to see if the webview will render the content. Note that they may be using various Javascript libraries which don't work well with Android which is why you are seeing the 'simplified' content.
Related
I want to view favicon.ico in the browser but not download them to my computer. How do I enforce that?
punch line
I have an app that is supposed to display favicons given a url. The app is successful only when the favicon.ico would display in browser as opposed to downloading. So I need to somehow force the image to display in browser. For example http://www.nydailynews.com/favicon.ico does not display in browser but rather downloads (chrome browser). But I see that safari is able to force it to display in browser. How can my android app do the same, as safari?
From android I am using picasso to load the images in a ListView
This is not a solution, but I'm not really sure what you're trying to do. Favicon does load in the WebView, it doesn't download it. I just tried the following code,
WebView view = (WebView) findViewById(R.id.web_view);
view.loadUrl("http://www.google.com/favicon.ico");
And this loads the icon in the WebView. Also I tried opening the same url in my Chrome Android app and it works too. It doesn't download it.
P.S. Note that I'm testing on Motorola Moto X running Android 5.1.
Update
Try this
WebView webView = (WebView) findViewById(R.id.web_view);
String data = "<body>" + "<img src=\"http://www.nydailynews.com/favicon.ico\"/></body>";
webView.loadData(data, "text/html", "utf-8");
I am trying to display a PDF to a web page using the html [object] tag. This works fine on all the web browsers on PC's as well as iPhone/iPad. But when I load the same page on an Android it asks me if I want to download the file which is the backup when the PDF isn't displayed. Does anyone know why this wouldn't work or another html control I could use rather than forcefully calling the local PDF program on the phone.
Below is how my html is rendered.
<object data="../myFile.pdf" type="application/pdf" width="100%" height="100%">
<p>Missing PDF plugin for this browser.Click here to download the PDF file.</p>
</object>
I have also seen examples on stackoverflow suggesting the below code but I am unsure of how to leverage it on my site and was hoping there was a possible html fix.
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("URL/Demo_PDF.pdf");
The phone I am using is a Thunderbolt. Thanks for the help.
Does anyone know why this wouldn't work
Because that is not supported on Android.
or another html control I could use rather than forcefully calling the local PDF program on the phone.
There may not even be a "local PDF program on the phone". Many phones ship with one, many users install one, but there is no guarantee.
But, beyond that, there is no way to display PDFs natively inline in the stock Android browser. A third party one might support it (e.g., Firefox). Converting the PDF to a Flash animation might work with the stock Android browser, though that will only work on Android 2.2 and higher.
but I am unsure of how to leverage it on my site
You wouldn't. That is Java code, for an Android application.
I want to display swf into a webview. The swf didn't display in the web view. I have this message fail(the browser should render some flash content, not this).
So I try this code. But I am getting ,swf file in encoded form in webview.
What to do to display this swf??
String url ="file:///android_asset/hoge.swf";
WebView wv=(WebView) findViewById(R.id.WebView01);
wv.getSettings().setPluginsEnabled(true);
wv.loadUrl(url);
swf is a flash file.
to be able to display flash file, the device should be supporting flash. recently, there's many android device not support flash. so you must be careful. also check whether the device is already installed flash plugin or not.
Lots of questions have been posted regarding this. Check out this question Load an SWF into a WebView
The author their says that you must enable plugins for thewebview
webview.getSettings().setPluginsEnabled(true);
I am making an application that creates and allows the user to edit an HTML file by adding notes and / or links to it. It then allows the user to sync it via dropbox so that they can view the file from any other Android device, or from a browser on their computer. In this program I have a WebView which loads the html page and shows it to the user. However if I tell the webview to load the shortened version of the URL(E.g. http://db.tt/DrSmhwq) instead of putting it inside my WebView it opens it in the browser on top of my app. If I use the long version of the URL(E.g. http://dl.dropbox.com/u/5724095/DBNotes.html) it loads it inside my WebView just fine. So I have a few questions: What is the difference between the shortened URLs and the long ones? Is there something about the URL that is causing this behavior, or is it more likely that this is an issue with the Android WebView? And does anyone know if there a way to generate the long versions of the URLs from within the dropbox Android app? Otherwise I am going to have to direct my users to go to the website on their computer and generate the long link and type it in to my app, this does not seem like a good solution.
Edit:
I made a bitly url that points to the longer dropbox url and tried to call wv.loadUrl() on that, it also opened up the browser instead of loading it into the WebView. So I am guessing that this is the default behavior for how the WebView handles redirects. Does anyone know how I can make it load the page that its directed to inside itself instead of a browser window?
What is the difference between the shortened URLs and the long ones?
The server is issuing a redirect, which you are not handling, so the default WebView behavior is invoked -- open the new URL in the browser.
Does anyone know how I can make it load the page that its directed to inside itself instead of a browser window?
Implement a WebViewClient, particularly shouldOverrideUrlLoading(), to handle the redirect. Attach an instance of your WebViewClient to your WebView via setWebViewClient().
I have an app where I've button on a webpage that is rendered inside a webview.
Now on click of button , a pdf file gets downloaded , and the same would then need to be opened inside the same webview.
attach a download listener to the web view and change the url as follows..
"https://docs.google.com/gview?embedded=true&url=https://www.example.com/xxxxxyyyyyxz.pdf"
example
https://docs.google.com/gview?embedded=true&url=https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf
it's a link used to open pdf without downloading it...
I hope it solves your problem..
I've found that the google viewer seems to work within the android browser for viewing online PDF files. You could build a link to your pdf so that it is displayed in the viewer. I've not tried doing that within a WebView though.
UPDATE
The link is dead, there is an explanation of how to get the functionality to still work at this link.
In case this link also dies, here is the relevant section:
While the page is no longer available as it redirects to Google Docs/Drive, you can still use the Google Docs Viewer. Paste this URL in a new tab:
https://docs.google.com/viewer?url=
and then paste the address of the document you want to view online. Here's an example:
https://docs.google.com/viewer?url=http://research.google.com/archive/bigtable-osdi06.pdf
I do not think that the present android chrome based browser can support pdf. There are discussion about the same in android forums ( ex: link1 link2)
Your best bet to show pdf is to have adobe pdf reader for android installed.(or concisely put, not possible in web view)
I don't think any browser other than Chrome supports rendering PDFs without a plugin or third party tool. It's probably easier to let the user use his own app to open PDFs.
I used the IText PDF library mentioned in this thread
Android : Is there any free PDF library for Android for a sample project. You could try getting using this API to get the PDF page as an image. I am not familiar with every aspect of Itext so it might have better way to do this.