Get the main content from RSS Feeds - java

I've created an application which lists all the feed items in ListFragment. My question is how to load the full text from the link. I've tried with WebView, but it is loading the complete URL. Since RSS XML structure does not have any tags related to full/actual content, can anyone give some reference so that I can use it?
This is how I've tried to load the URL in WebView:
URL = getIntent().getStringExtra("url");
webView = (WebView) findViewById(R.id.activity_display_news_webview);
webView.loadUrl(URL);

You can use boilerpipe to extract the full text from the url

Related

Android - Show Local Images in WebView [duplicate]

This question already has answers here:
Android - local image in webview
(11 answers)
Closed 6 years ago.
I found out that in earlier APIs of android (KitKat and abover), local images (for example pictures in assest folder) can't be load in WebView! I have a html file that contains tag to show images.
<img src="blacksmoke1.jpg">
And I put blacksmoke1.jpg in assest folder. but nothing shown in WebView.
This is the problem: https://code.google.com/p/android/issues/detail?id=63033
How can I fix it? Is there an alternative way to show pictures in webview? Or Is there a custom WebView that i can implement in my app?
Edit:
This my assest folder:
Try creating a web pages in your assets directory and creating HTML pages that display the images. Then call a web page using this:
webview.loadUrl("file:///android_asset/blacksmoke.html");
Or, according to one of the posts in your link, move the html file to a server and use this code:
loadDataWithBaseUrl("content://<your contentProvider>/blacksmoke.html", ...);
Code in blacksmoke.html could be:
<!DOCTYPE html>
<!-- Perhaps some JQuery mobile for more functionality and control over which images get displayed and why etc -->
<body>
<div><img src="image/blacksmoke1.jpg"></div>
</body>
</html>
Here is a good explanation for creating native pages or displaying native images.
This is what I do to load local resources in webview from assets folder:
StringBuilder sb = new StringBuilder();
if (notification.get_id().equals("53be76c3d6eac5f54a546176")){
sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <title>For.... <img src=\"data1/images/forum1.jpg\" alt=\"\" title=\"\" id=\"wows1_0\"/> </body> </html>");
That is the html i want to load, if you notice there is an img tag, loading an image from data1 folder which is placed in assets folder. In order to be able to load resources from there I do the following:
WebView webView = (WebView) findViewById(R.id.webview);
webView.loadDataWithBaseURL("file:///android_asset/", sb.toString(), "text/html", "utf-8", null);
Hope it helps

Images are not showing in pdf created using velocity template

I create pdf using Velocity template, but i am not able to put images in pdf.
I am adding url into context object and accessing that object into eot.vm file, url is going proper but still images are not displaying in pdf.
Thanks & Regards,
Tushar
Make sure that URL you are passing is sending IMAGE as response not an full html page.
i was passing URL that was sending me a whole html page, so i was unable to see images.
But now its fixed.
Please visit below link:
https://answers.atlassian.com/questions/2907/how-to-access-image-generated-via-velocity-template-confluence

display html in popup

What we do is we define a webview and make the html files being displayed in that. Is it possible to display an html file in android's default pop up on the same screen? I have stored the html file in assets/www folder.
Please let me know regarding this
It is possible to display a WebView or any other UI in a default Android Dialog. But, it is better and easier for you to make your own custom Dialog class and display the WebView in that. You can also make it an Activity and use the Dialog theme to make the Activity look and behave like a Dialog.
You are correct to put your .html file in the "assets" folder. That is what I do.
Load the WebView like this:
private final static String url = "file:///android_asset/file.html";
webview.loadUrl(baseUrl);

Java Android WebView Displaying a string

i have an application that fetch html from a websites, exactly in a webpage permitted only tu logged in user, so i have setted the login cookie and i get back the html webpage to a string, i tryied to easily take this string off from emulator, but i can't do copy-paste trought emulator-pc, does someone know how can i load a webview to reder my string and make me seeing if i am logged in and all work or not?
If it's possible i'd like to directly render the string, without saving it to an html file and opening it... is this possible?
Thanks, matteo.
Setting webview content form String:
public static void loadHtmlToWebView(WebView view, String html) {
view.loadData(Base64.encodeToString(html.getBytes(), Base64.DEFAULT) , "text/html", "base64");
}

WebView not Loading Data?

I'm trying to load the parsed html data from an rss feed using a
WebView, but the webview claims that the page:
"data:text/html;utf-8,[The html I'm trying to display]"
is not available.
I find it strange that it seems to be putting the html data into the
url, when I just want it to display it.
Here's my code right now for the webview:
Bundle data = getIntent().getExtras();
WebView webview = new WebView(this);
setContentView(webview);
webview.loadData(data.getString("DEFAULTTEXT"), "text/html", "utf-8");
Where the HTML has been passed in a string in the Bundle with the
identifier: DEFAULTTEXT. I've tested the class and the HTML is passed
fine, it just isn't displayed correctly.
It works fine on some of the webpages I've tried, but not others. I'll try to post the code of one that works and one that doesn't.
Huuu.... so I turned my computer on this morning and it worked perfectly. I still don't know what the problem was. :/
Edit: Never mind. It works on some, but not all of the pages I try to display.
Edit2: swapping it out for loadDataWithBaseURL worked like a charm.
As stated, when you have characters like '%', '\', '#' in your HTML, it needs to be escaped which loadData doesn't seem to do automatically.
loadDataWithBaseURL instead of loadData does escape and seems to fix this. Just use null for baseUrl and historyUrl. So the example code in the question is changed to:
Bundle data = getIntent().getExtras();
WebView webview = new WebView(this);
setContentView(webview);
webview.loadDataWithBaseURL(null,data.getString("DEFAULTTEXT"), "text/html", "utf-8",null);
I believe this sporadic behavior of loadData* is because of what is the content of the page you are trying to load. If it is plain simple html it has no problem. But if it has components like css or other features requiring external info, it will bail out.
My experience!
Are you sure you have the correct permissions defined in the manifest.xml?

Categories