4

I have a problem with storing avatars. My app got user's detail with image (image is in byte[] array). How to store this images in my app? I mean should I save every user's image in internal or external storage? Or should I use this image in time and set as ImageView? What is best solution for my problem?

Thanks for help:)

7geeky
  • 438
  • 1
  • 12
  • 26
Magnus2005
  • 97
  • 3
  • 13
  • you can save data in sharedpreferences. – comeback4you Jul 14 '16 at 06:53
  • What have you already tried, why didn't it work? Does the avatar change often? Is it just about one user's avatar or hundrets of images? Where do the avatars come from? How big is one? There is no "best solution" that always is the best, it depends very much on what you are trying to do. – Gumbo Jul 14 '16 at 06:53
  • You can encrypt to Base64 and save to database with data type is BLOB. – Iris Louis Jul 14 '16 at 06:53
  • For example there is 1k users of my app. Every user has an avatar. Every avatar is stored in server. My app get every user details with image. And there is a problem. What should I do with every image? A) save every image in in/external storage in some folder "avatars" and after set as ImageView with path into image, or B) after I get image from server convert into Bitmap and set in ImageView? o C) give me advice :) – Magnus2005 Jul 14 '16 at 06:58
  • If you want sync data with client, i think you save data in server. If you think it not importand... you can save to external. – Iris Louis Jul 14 '16 at 07:03
  • Use *Picasso* or *Glide* for managing the bitmap caching and loading – OneCricketeer Jul 14 '16 at 08:25

2 Answers2

3

There are advantages and disadvantages in storing images in internal storage. It also largely depends on your apps' business logic. In the android documentation here it is explained very well.

Internal storage:

  1. It's always available.

  2. Files saved here are accessible by only your app.

  3. When the user uninstalls your app, the system removes all your app's files from internal storage.

External storage:

  1. It's not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.

  2. It's world-readable, so files saved here may be read outside of your control. When the user uninstalls your app, the system removes your app's files from here only if you save them in the directory from getExternalFilesDir().

Community
  • 1
  • 1
Seagull
  • 1,063
  • 1
  • 11
  • 18
0

First convert byte array into Bitmap

Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);

And store bitmap into external storage as file

Convert Bitmap to File

Community
  • 1
  • 1
Nilesh Senta
  • 5,236
  • 2
  • 19
  • 27
  • Thank you. But if my app uses 1 milion users so it will take a lot of space of my storage? Am I right? – Magnus2005 Jul 14 '16 at 07:03
  • Yes it will use a lot of space. Most of the new apps download the content from the server and rarely store info locally. In your case you can store the users' favourite contacts and their avatars on the device or cache the most recent. It depends on the app logic. – Seagull May 26 '17 at 12:26