Since posting a link to my simple RSS Reader for Android implemented using a custom SAX parser I have some questions regarding upgrading to handle images - I have previously posted on how to implement new tags in the feed that you want to handle (including nested tags) - but one question I received was regarding when images are just embedded in the text (e.g. not a specific image tag, but say as part of a description as HTML).
So, I have updated the code (uploaded, see the sidebar) - this time it parses the description text data to retrieve any Image links its pretty grim string manipulation, but it does the job!
First I needed to change the Article class to parse the link. I updated the setDescription method to also check for IMAGE tags to parse, if any found then it would set the ImgLink member:
I then also had to update the RssListAdapter class - this needed the necessary action to pull down the link based on our parsed URL and then inflate the ImageView in our row:
So, I have updated the code (uploaded, see the sidebar) - this time it parses the description text data to retrieve any Image links its pretty grim string manipulation, but it does the job!
As you can see, it now parses the image URL from the description and inserts it to the left of the feed item.
What did I change?First I needed to change the Article class to parse the link. I updated the setDescription method to also check for IMAGE tags to parse, if any found then it would set the ImgLink member:
- public void setDescription(String description) {
- this.description = description;
- //parse description for any image or video links
- if (description.contains("<img ")){
- String img = description.substring(description.indexOf("<img "));
- String cleanUp = img.substring(0, img.indexOf(">")+1);
- img = img.substring(img.indexOf("src=") + 5);
- int indexOf = img.indexOf("'");
- if (indexOf==-1){
- indexOf = img.indexOf("\"");
- }
- img = img.substring(0, indexOf);
- setImgLink(img);
- this.description = this.description.replace(cleanUp, "");
- }
- }
I then also had to update the RssListAdapter class - this needed the necessary action to pull down the link based on our parsed URL and then inflate the ImageView in our row:
- if (jsonImageText.get("imageLink") != null){
- String url = (String) jsonImageText.get("imageLink");
- URL feedImage= new URL(url);
- HttpURLConnection conn= (HttpURLConnection)feedImage.openConnection();
- InputStream is = conn.getInputStream();
- Bitmap img = BitmapFactory.decodeStream(is);
- imageView.setImageBitmap(img);
- }
I can't find the source code? :(
ReplyDeleteHi Kenny
ReplyDeletePlease find the Source code here
http://www.thirdmindmedia.co.uk/source/android/SimpleAndroidRSSReader_0.2.zip
Thanks for reply
This comment has been removed by the author.
ReplyDeleteHi Krishna
ReplyDeleteis there a possibilty if you wan't to read a certain topic you can open it by a simple click?
thanks for reply
Hi Kevin
DeleteOpen the particular link in the onclick event of the list
I am used this code but mostly finding blank titles some times.
ReplyDeleteAfter some titles it display the data .
so canyou please guide me where is the error.?
Hey Krishna if U still helping on this code please reply
ReplyDeletehave some problems
its urgent
Could anyone send me the whole code on my email.
ReplyDeletetounsihouweida@gmail.com
thanks
There are problems when rss feed don't containt an image... How to fix it? Please, help me :(
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete