0

I'm building an app which will allow the user to upload their own icons for use within the app (these will be small .png or .gif files). I want to include a default set of icons, and then allow the user to add their own.

I'm trying to figure out the best way to do this - there seem to be various solutions online and I'm not sure which is best for my purposes. As I said, I'd like to supply a default set of icons with the app, to be stored on the user's device. The user should then be able to add more icons, which should also be stored on the device (at some point later on the user can choose to upload the icons to a central server so that other people can use them too).

Currently I've tried adding the default .png files manually to Android Studio's 'drawable' folder, and then storing the resource id in the database. The resource id seems to keep changing, though, so the wrong icon is being loaded most of the time. So, instead I believe I need to store the name/path of the .png file in the database. Would that be correct? If so, is there a standard file path that leads to the 'drawable' folder?

And what about the user uploading icons? Should I just save these to a particular directory, and then store the path in the database? Or is there a better way to handle this?

What kinds of things should I be considering? The icons should be 64x64 max, or thereabouts (I haven't totally decided yet, but they won't be much bigger than that - we're not talking about 1000x1000 or anything). In theory the user can add as many as they want, but in practice I imagine most will use the default set, and a few will add up to 20-30 icons of their own.

All advice welcome! Thank you.

Sharon
  • 2,841
  • 8
  • 42
  • 69
  • you said the drawable id is changing? how is that possible, if the drawable is called mypic the res id is R.drawable.mypic, how could it change – Tomer Shemesh Jun 02 '16 at 17:15
  • 1
    for images i would upload them to getExternalFilesDir(Environment.DIRECTORY_PICTURES) – Tomer Shemesh Jun 02 '16 at 17:16
  • I'm not sure, Timer - i was storing the id (integer), if that makes a difference? – Sharon Jun 02 '16 at 17:21
  • Sorry, Tomer (autocorrect changed your name) – Sharon Jun 02 '16 at 17:21
  • 1
    Ah yea you cant do that, just storing the int of the id wont work because that changes anytime the resources are changed, you should store the name of the drawable like this http://stackoverflow.com/questions/6677804/android-drawable-id-change-after-resources-modify – Tomer Shemesh Jun 02 '16 at 17:30
  • 1
    you could use assets instead of drawables, those have a "path", or you store drawables by name: http://stackoverflow.com/questions/16369814/how-to-access-the-drawable-resources-by-name-in-android the rest sounds good. I wouldn't restrict to size in pixels but dp so you don't enforce tiny icons on high res displays. Or resize whatever the user supplies. – zapl Jun 02 '16 at 17:31
  • Thank you! Hadn't thought about dp rather than pixels, so that's a good point. – Sharon Jun 02 '16 at 17:32

1 Answers1

1

Read about internal and external storage in Android here: https://developer.android.com/guide/topics/data/data-storage.html

The only difference is that in internal storage the images/data is not accessible by users if they say, plug their phone into their computer and try to view the files. In external storage all items are public.

For some sample code on how to have users save images in your app take a look at this SO post: Saving and Reading Bitmaps/Images from Internal memory in Android

You can then just store the filenames of the icons in shared preferences (if you don't anticipate that many icons and your model is simple) or SQLite if your model is more complex. Since you sound like a beginner I would recommend start with shared preferences?

As for the default icons you store with your app, yes you can put them in the drawables folder (with different sizes for different screens if you are doing that thing), but since you already know the names of those drawable resources can't you just display whatever one you want with Java when you need to? I am not sure what the reason would be to store those in a database but then again I have no idea what you are building.

Hope this helps.

Community
  • 1
  • 1
Micro
  • 9,083
  • 8
  • 68
  • 104
  • Thank you, that's really helpful. I'll read up on it all tomorrow. I'm thinking of putting the defaults into the database just so that they'd be stored in the same way as the user-added ones and can be used in the same way. – Sharon Jun 02 '16 at 17:30