Android Question How to save image to SQL blob fields after downloaded from url?

eSolution

Member
Licensed User
Longtime User
Hi,
I get a JSON string from a webservice (like Facebook Graph). Among the "items" that I got when parsing the JSON string are image urls. I want to save all of my items in a SQLite database table but I want to download the image, transform it in to a BLOB and save it in this format in the table. I have seen examples on how to transform an image file in a BLOB. The ImageDownloader service is saving the downloaded image to a imageview ...

Does anyone have a code snippet on how to put all this together?

Thank you!
 

eSolution

Member
Licensed User
Longtime User
I did that and it worked!

Thank you Erel!!!
 
Upvote 0

eSolution

Member
Licensed User
Longtime User
I also think that the code for getting the image from the database and putting it in to the imageview of the CustomListView is wrong, all the images in my clv are white (but at least I don't get an error while trying to initialize the bitmap)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I took you project and instead of working with your Customlistview, I used a conventional listview, I did the following modifications:
1. I populated the database from your website by clicking the button: Populate Database'
2. I created an additional activity that has a layout with a two lines and bitmap listview. and loaded by clicking 'Display Database' button. I can see all the photos, the VIDID and TITLE on each listview record.
2. Next, whenever I click on an item another activity opens up with a new layout that has a full screen image view, where I display the photo with its corresponding identifiers like the VIDID and TITLE. You can continue to see any record with the image as long as you want.
3. I did not try your customlistview because I am not too swift with it and you mentioned that you had trouble with it.

Summary: While the pictures were downloading from your site, there was for a slight moment toastmessage: error, but all pictures downloaded ok. I can view all and any record in the listview and imageview.
Attached is the full project I worked with. Please keep it separate from your own, so you do accidentally overwrite your own project. I did not delete any of your code in my project, just commented some. It is just to illustrate that all the data is there. The problem might be your customlistview code, which I did not mess with.

ADDENDUM 1: I played around later with your own version of the program and your Customlistview when I spared some time. Here is what you need to do to see the blobs in the imageviews:
Comment this line: imgvYT.Initialize("imgvYT") in the Main activity.

ADENDUM 2: Sorted records by title number which is embedded in the title text so it looks more ascending. Title number in your database is not a column by itself. I uploaded it again here.
 

Attachments

  • eSolutionDB__Modified_Mahares_021716.zip
    19.3 KB · Views: 229
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
This post has your original app attached that I tweaked . your CustomlistView needed some tweaking. I changed the layout so it looks more readable. You can adjust more if you want. All imageviews fill up. I even sorted your records by tutorial number even though you have the tutorial number inside the title and not a column by itself.
Now you have my app in the previous post and yours here tweaked in this post. You can choose to fine tune your final project based on a conventional Listview project and and a Customlistview project..
 

Attachments

  • eSolutionDB_Original_Modified_021817.zip
    15.5 KB · Views: 206
Last edited:
Upvote 0

eSolution

Member
Licensed User
Longtime User
Thank you for finding the "bug" in it, I was about to reply that I can also make the app show the images in a new activity but I change the content of that pContent panel instead of accessing new activities so I need my clv working on that panel but you found the bug. I will test your code now.
by the way, my clv in this sample project was just for testing, is not the final layout (this is just 1/5 from the entire project, the project include feeds from facebook, twitter, rss and so on and a material design).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…