Free Shipping

Secure Payment

easy returns

24/7 support

  • Home
  • Blog
  • Save and Retrieve image from SQLite in Android

Save and Retrieve image from SQLite in Android

 July 15  | 0 Comments

This blog is for beginners who wants to work with SQLite for storing images & retrieving the same in Android device.

Here, in this blog we will be inserting and displaying an image from SQLite database.

SQLite: SQLite is an open source SQL Database in local devices. It stores data to a text file onto a device. SQLite is a light weight database which comes in-built with Android OS.

Let’s go through each and every step to acquire the required results

1. Create a New Project and give name as ‘SQLiteDemoActivity’ and click Next.

 

2. Select the form factor on which you want to run your app and click on Next.

 

3. Add a blank activity to Mobile and click on Next.

 

4. Customize your activity and click on Finish.

 

5. Building “SQLiteDemoActivity” Gradle Project Info.

 

6. In activity_main.xml, Add one ListView.

7. Add one more layout named as screen_list.xml and add ImageView and TextView on it.

 

8. Add a code in MainActivity.java for Image Bitmap and store into the SQLite.

 

 

 

You have to add Name and Image like above code in Get() and Set().

10. Create an Adapter for getting a view and set an Image in List.

 

 

}

11. Create a DatabaseHandler class for Handling a Database. For this, you should extend SQLiteOpenHandler class.

In onCreate(), create a Table consisting of 3 columns – id, name, photo/image

// Creating Tables

In onUpgrade(), upgrade a Table

Adding a new Contact

Getting a single Contact

Getting All Contacts

Updating Single Contact

Deleting Single Contact

Getting Contact Counts

12. Run your app and you will get an output like below:

 

 

About the Author

Hitesh Patel, currently working at AcadGild has two years of solid professional experience in designing and developing Android applications to his credit. He is an expert in Android app development using Eclipse IDE, Android Studio, Java, Web Services (JSON, XML), SQLite, Android SDK, and ADT plug-in.

He is proficient in common Android framework APIs (Telephony, Location, Maps, GCM) and is passionate about explaining it to others. He is an active blogger and has several projects developed by him in his bag.

Feel free to contact him at hitesh@acadgild.com in case you have any query.

>