0

I am working on an Android app like Notepad.

There are two sections.

  1. Text Only
  2. Text with images

A notepad which can only get text from user and save it in db and then retrieve is done.

The another section, will work basically like MS Word.

User can select image from gallery and save it in notepad.
But how can I achieve it? Because I want to store that whole data (image & text) into db as it is. Means suppose user added an image after 2 lines of text. Then app should retrieve it from db in that format only.

Any suggestions? Please help me. Thanks in advance.

K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
varsha valanju
  • 801
  • 1
  • 9
  • 27
  • You can save image a BLOB format. For reference: http://stackoverflow.com/questions/9357668/how-to-store-image-in-sqlite-database – Barış Söbe Oct 20 '16 at 15:17
  • ya right.but how can i retrieve the full note from db. i.e image n text.. in the same format the user wrote n saved – varsha valanju Oct 20 '16 at 15:22

2 Answers2

0

You can save the byteArray or uri of images in the database.

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray();

String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); Uri uri = Uri.parse(path);

Hope this helps ....

Anuraj Jain
  • 85
  • 10
0

The most simple solution would be to define tags or some other form of markup language, that would store that image within a text as a path to file on Disk for example which is imho better alternative than storing it in SQLite but if you insist on database, you can store something like an imageId and keep it the there... However, you are manually doing something, that has already been optimized for you when trying to handle the byte array instead of a file in memory ..

Once you store images in this custom markup language, you can parse it and split the text on chunks between the images which you populate dynamically to some ViewGroup(i.e. LinearLayout) as separate TextViews and ImageViews...

Finally, if you want a solution quickly, you can use some already developed libraries such as this : https://android-arsenal.com/details/1/1696 ... However, this pattern is so common that you can find a great number of libraries that do exactly the thing you are looking for ...

Don't reinvent the wheel if it's not necessary..

koperko
  • 2,447
  • 13
  • 19