Android XML Rich Text Processing - android

I used the tutorial listed here to parse my XML:
http://android-er.blogspot.com/2010/05/simple-rss-reader-iii-show-details-once.html
The problem I am having is when I try to read in the XML description tag all I get is this:
The "<" symbol is where the description should go. This is the feed I am reading: http://www.calvaryccm.com/rss/devos.ashx
Please help me solve my issue in getting the real text into the description. Thank you!

I just created an android project in eclipse using the code I downloaded from the site you listed above. I only made one modification to the original sources. I changed line 33 in AndroidRssReader.java to read:
URL rssUrl = new URL("http://www.calvaryccm.com/rss/devos.ashx");
The feed loads and parses fine.
The parsing error is the result of changes you made to the original sources.

If the data is html encoded, you can use one of the following methods -- or if it is unencoded, you can surround the content in CDATA tags.
Spanned spannedContent = Html.fromHtml(htmlString);
textView.setText(spannedContent, BufferType.SPANNABLE);
or
WebView webview = (WebView) findViewById(R.id.aWebView);
String htmlString = "<html><body>Some html</body></html>";
webview.loadData(htmlString, "text/html", "utf-8");

I found out that I need to wrap my RSS tags in CDATA Tags as shown here:
Writing input for .NET web services

Related

Symbols show up as � after i parse an html webpage using jsoup and display contents in android listview

I would like to understand this problem i have been having.
Im parsing an html source page and displaying the content i want in a list view in android.
I parse the page using this command.
doc = Jsoup.connect(myURL).get();
Symbols such as é or “ ” show up as �.
I understand they are not being recognized by the encoding mechanism but is it because of jsoup or android?
Android default encoding im using is Utf-8 should it not support that?
If it should not how and what should i change it to?
Thank you for you help.
é in ISO-8859-1 (extend ASCII) is the value 233 but in UTF-8 it is the value 195 folowed by 169.
You need to know in what encoding the caracters are saved in because only the values are saved and then interpreted.
Thank you guys for the help.
making the jsoup call like this :
Document document = Jsoup.parse(new URL(url).openStream(), "ISO-8859-1", url);
was the way to go i then had to find out the real encoding of the webpage in chrome you can find it in 'more tools' and in my case it was
windowns-1252. One line of code solved the problem:
doc = Jsoup.parse(new URL(url).openStream(), "windows-1252", url);

How to retrieve url of an image on website

I am developing an application which shows a image from a site on button click.
I learned that concept and did it. But now the problem is on each day image changes on that site and i want to display that new image.
So how can i get the url for that new image?
That site has only one image so i hope if this helps for the solution because i am not getting answer for this over internet.
You can visit site to be clear. If any doubt so please ask in comments and please don't select it as off topic as its related to programming.
Parse it from that html page source. You can use Jsoup
String webUrl = "http://www.yoursite.com/";
Document doc = Jsoup.connect(webUrl).get();
Elements element = doc.getElementsByClass("header");
String elementText = element.text();
You should parse a XML RSS feed. For parsing XML RSS feed you need to use the 'xmlParser' of JSoup.
You want to get the image URLs. The image URLs are in the 'enclosure' tag with attribute 'url'. They is no 'img' tag in the RSS feed. So, you need to read the 'enclosure' tag and not the 'img' tag.
I am attaching the code below to pull the image URLs. This code has been tested by me. Let me know in case of any issues.
String url = "http://www.uefa.com/rssfeed/news/rss.xml";
Document doc = Jsoup.connect(url).parser(Parser.xmlParser()).ignoreContentType(true).get();
for (Element x : doc.getElementsByTag("enclosure")) {
System.out.println(x.attr("url"));
}
You Should parse RSS feed from this url http://apod.nasa.gov/apod.rss
for parsing RSS you can use sax parser
You can see this link to use the sax parser http://samir-mangroliya.blogspot.com/p/android-sax-parser.html
hope can help you

Android Display .Doc File in WebView?

In my app,I have link http://mymobilece.com/api/api_getexammaterials.php?id=28,
I want to view in webview ,I try with google document viewer its work fine But i need it without google document viewer,How to show it??
you can use the js for google Doc viever
myScript="<html><iframe src='http://docs.google.com/gview?
url='http://mymobilece.com/api/api_getexammaterials.php?
id=28'&embedded='true' style='width:600px; height:500px;'
frameborder='0'></iframe></html>"
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadData(myscript,"text/html", "UTF-8");
you can use myscript as string variable and use this javascript code(please make sure to remove double quite if above code) and load in webview
You can change the url - width- height variables according to your scripting.
Docs.google.com has a document parser , which basically parses MS-Office files , thats why you can view it on google docs. without that you will have to write document parser. Which will parse files and fetch the contents to display on view. In Short it will be not a good idea to do that. :)

How to display an html code(which parsed xml) on android application

I am an android developer. I'm calling web service for one functionality and getting following code as output, when the web service is called.
<string xmlns="http://tempuri.org/">
<Response>
<Response_Code>0</Response_Code>
<Response_Description></Response_Description>
<Description></Description>
</Response>
</string>
In between the Description tag i get html code.
I want to display this on android app.
Can anybody tell me, how i can do this?
Thanks
use the following code as taken from http://developer.android.com/reference/android/webkit/WebView.html
and use a webview to display the data as:
String summary =<WHATEVER IS IN YOUR DESCRIPTION TAG> ;
webview.loadData(summary, "text/html", "utf-8");
You could also use the Html class.
someTextView.setText(Html.fromHtml(descriptionText));

Is there any way to have WebView auto-link URLs and phone numbers in Android?

If a page has a URL or a phone number on it that isn't a link is there any way to have WebView recognize it and automatically turn it into a link like you can with TextViews?
With a TextView you would simply set the android:autoLink to the desired settings:
<TextView
android:autoLink="web|phone"
... />
but I can't find any equivalent for WebView.
If you are loading your own (web) content from a String, then you can do something like this:
final String content = "My email is: firstname#email.com ...";
Spannable sp = new SpannableString(content);
Linkify.addLinks(sp, Linkify.ALL);
final String html = "<body>" + Html.toHtml(sp) + "</body>";
myWebView.loadData(html, "text/html", "utf-8");
I don't know about any way which would make this work just by changing a setting, but a workaround would be to wait until the web page finishes loading and then do:
yourWebView.loadUrl("javascript:(function(){ /* code that creates links */ })()");
This will inject javaScript into the already loaded web page.
There's a slightly longer example available here: http://lexandera.com/2009/01/injecting-javascript-into-a-webview/.
You can find the JavaScript source for creating links if you take a look at the source of Linkify script for Greasemonkey (it's a plugin for Firefox in case you're not familiar with it). I believe it comes with the default install.

Categories

Resources